From f7dff2e661a54bee770940ee1ebd9eab6456ba2e Mon Sep 17 00:00:00 2001 From: Dan Imhoff Date: Sun, 29 Nov 2020 13:46:36 -0600 Subject: [PATCH] fix(ios): share message handler between webview and bridge (#3875) --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 5fd263b2ef..4146d8c868 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -61,17 +61,17 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKUID // get the web view let assetHandler = CAPAssetHandler() assetHandler.setAssetPath(startPath) - webView = prepareWebView(with: configuration, assetHandler: assetHandler) + let messageHandler = CAPMessageHandlerWrapper() + webView = prepareWebView(with: configuration, assetHandler: assetHandler, messageHandler: messageHandler) view = webView self.handler = assetHandler // configure the web view setKeyboardRequiresUserInteraction(false) // create the bridge - let messageHandler = CAPMessageHandlerWrapper() capacitorBridge = CapacitorBridge(with: configuration, delegate: self, cordovaConfiguration: configDescriptor.cordovaConfiguration, messageHandler: messageHandler) } - private func prepareWebView(with configuration: InstanceConfiguration, assetHandler: CAPAssetHandler) -> WKWebView { + private func prepareWebView(with configuration: InstanceConfiguration, assetHandler: CAPAssetHandler, messageHandler: CAPMessageHandlerWrapper) -> WKWebView { // set the cookie policy HTTPCookieStorage.shared.cookieAcceptPolicy = HTTPCookie.AcceptPolicy.always // setup the web view configuration @@ -84,7 +84,6 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKUID webViewConfiguration.applicationNameForUserAgent = appendUserAgent } webViewConfiguration.setURLSchemeHandler(assetHandler, forURLScheme: configuration.localURL.scheme ?? InstanceDescriptorDefaults.scheme) - let messageHandler = CAPMessageHandlerWrapper() webViewConfiguration.userContentController = messageHandler.contentController // create the web view and set its properties let webView = WKWebView(frame: .zero, configuration: webViewConfiguration)