瀏覽代碼

fix(iOS): resetupScripts now actually uses the WKWebViewConfiguration that it takes

Jamie Birch 5 年之前
父節點
當前提交
eb67ce7fd1
共有 1 個檔案被更改,包括 10 行新增10 行删除
  1. 10
    10
      ios/RNCWebView.m

+ 10
- 10
ios/RNCWebView.m 查看文件

1022
 }
1022
 }
1023
 
1023
 
1024
 - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
1024
 - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
1025
-  [_webView.configuration.userContentController removeAllUserScripts];
1026
-  [_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHandlerName];
1025
+  [wkWebViewConfig.userContentController removeAllUserScripts];
1026
+  [wkWebViewConfig.userContentController removeScriptMessageHandlerForName:MessageHandlerName];
1027
   
1027
   
1028
   NSString *html5HistoryAPIShimSource = [NSString stringWithFormat:
1028
   NSString *html5HistoryAPIShimSource = [NSString stringWithFormat:
1029
     @"(function(history) {\n"
1029
     @"(function(history) {\n"
1046
     "})(window.history)\n", HistoryShimName
1046
     "})(window.history)\n", HistoryShimName
1047
   ];
1047
   ];
1048
   WKUserScript *script = [[WKUserScript alloc] initWithSource:html5HistoryAPIShimSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
1048
   WKUserScript *script = [[WKUserScript alloc] initWithSource:html5HistoryAPIShimSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
1049
-  [_webView.configuration.userContentController addUserScript:script];
1049
+  [wkWebViewConfig.userContentController addUserScript:script];
1050
   
1050
   
1051
   if(_sharedCookiesEnabled) {
1051
   if(_sharedCookiesEnabled) {
1052
     // More info to sending cookies with WKWebView
1052
     // More info to sending cookies with WKWebView
1056
       // See also https://forums.developer.apple.com/thread/97194
1056
       // See also https://forums.developer.apple.com/thread/97194
1057
       // check if websiteDataStore has not been initialized before
1057
       // check if websiteDataStore has not been initialized before
1058
       if(!_incognito && !_cacheEnabled) {
1058
       if(!_incognito && !_cacheEnabled) {
1059
-        _webView.configuration.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
1059
+        wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
1060
       }
1060
       }
1061
       for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
1061
       for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
1062
-        [_webView.configuration.websiteDataStore.httpCookieStore setCookie:cookie completionHandler:nil];
1062
+        [wkWebViewConfig.websiteDataStore.httpCookieStore setCookie:cookie completionHandler:nil];
1063
       }
1063
       }
1064
     } else {
1064
     } else {
1065
       NSMutableString *script = [NSMutableString string];
1065
       NSMutableString *script = [NSMutableString string];
1106
       WKUserScript* cookieInScript = [[WKUserScript alloc] initWithSource:script
1106
       WKUserScript* cookieInScript = [[WKUserScript alloc] initWithSource:script
1107
                                                             injectionTime:WKUserScriptInjectionTimeAtDocumentStart
1107
                                                             injectionTime:WKUserScriptInjectionTimeAtDocumentStart
1108
                                                          forMainFrameOnly:YES];
1108
                                                          forMainFrameOnly:YES];
1109
-      [_webView.configuration.userContentController addUserScript:cookieInScript];
1109
+      [wkWebViewConfig.userContentController addUserScript:cookieInScript];
1110
     }
1110
     }
1111
   }
1111
   }
1112
   
1112
   
1113
   if(_messagingEnabled){
1113
   if(_messagingEnabled){
1114
     if (self.postMessageScript){
1114
     if (self.postMessageScript){
1115
-      [_webView.configuration.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
1115
+      [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
1116
                                                                        name:MessageHandlerName];
1116
                                                                        name:MessageHandlerName];
1117
-      [_webView.configuration.userContentController addUserScript:self.postMessageScript];
1117
+      [wkWebViewConfig.userContentController addUserScript:self.postMessageScript];
1118
     }
1118
     }
1119
     // FIXME: For a separate (minor) PR: these two shouldn't be gated by messagingEnabled; just keeping consistency with previous behaviour.
1119
     // FIXME: For a separate (minor) PR: these two shouldn't be gated by messagingEnabled; just keeping consistency with previous behaviour.
1120
     if (self.atStartScript) {
1120
     if (self.atStartScript) {
1121
-      [_webView.configuration.userContentController addUserScript:self.atStartScript];
1121
+      [wkWebViewConfig.userContentController addUserScript:self.atStartScript];
1122
     }
1122
     }
1123
     if (self.atEndScript) {
1123
     if (self.atEndScript) {
1124
-      [_webView.configuration.userContentController addUserScript:self.atEndScript];
1124
+      [wkWebViewConfig.userContentController addUserScript:self.atEndScript];
1125
     }
1125
     }
1126
   }
1126
   }
1127
 }
1127
 }