Procházet zdrojové kódy

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

Jamie Birch před 4 roky
rodič
revize
eb67ce7fd1
1 změnil soubory, kde provedl 10 přidání a 10 odebrání
  1. 10
    10
      ios/RNCWebView.m

+ 10
- 10
ios/RNCWebView.m Zobrazit soubor

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