GitToTheHub commented on code in PR #1664:
URL: https://github.com/apache/cordova-ios/pull/1664#discussion_r3387158035


##########
CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m:
##########
@@ -260,8 +248,21 @@ - (void)pluginInitialize
         wkWebView.navigationDelegate = (id <WKNavigationDelegate>)self;
     }
 
+    CDVWebViewWeakScriptMessageHandler *weakScriptMessageHandler;
     if ([self.viewController 
conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
-        [wkWebView.configuration.userContentController 
addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController 
name:CDV_BRIDGE_NAME];
+        weakScriptMessageHandler = [[CDVWebViewWeakScriptMessageHandler alloc] 
initWithScriptMessageHandler:(id < WKScriptMessageHandler 
>)self.viewController];
+    } else {
+        weakScriptMessageHandler = [[CDVWebViewWeakScriptMessageHandler alloc] 
initWithScriptMessageHandler:self];
+    }
+    [userContentController addScriptMessageHandler:weakScriptMessageHandler 
name:CDV_BRIDGE_NAME];
+
+    if(self.CDV_ASSETS_URL) {
+        NSString *scriptCode = [NSString 
stringWithFormat:@"window.CDV_ASSETS_URL = '%@';", self.CDV_ASSETS_URL];
+        WKUserScript *wkScript = [[WKUserScript alloc] 
initWithSource:scriptCode 
injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
+
+        if (wkScript) {
+            [userContentController addUserScript:wkScript];
+        }

Review Comment:
   Can you document this part?



##########
CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m:
##########
@@ -260,8 +248,21 @@ - (void)pluginInitialize
         wkWebView.navigationDelegate = (id <WKNavigationDelegate>)self;
     }
 
+    CDVWebViewWeakScriptMessageHandler *weakScriptMessageHandler;
     if ([self.viewController 
conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
-        [wkWebView.configuration.userContentController 
addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController 
name:CDV_BRIDGE_NAME];
+        weakScriptMessageHandler = [[CDVWebViewWeakScriptMessageHandler alloc] 
initWithScriptMessageHandler:(id < WKScriptMessageHandler 
>)self.viewController];
+    } else {
+        weakScriptMessageHandler = [[CDVWebViewWeakScriptMessageHandler alloc] 
initWithScriptMessageHandler:self];
+    }
+    [userContentController addScriptMessageHandler:weakScriptMessageHandler 
name:CDV_BRIDGE_NAME];

Review Comment:
   Can you document what's happening here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to