Skip to content

Commit

Permalink
fix(ios): share message handler between webview and bridge (#3875)
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd authored Nov 29, 2020
1 parent c31eb35 commit f7dff2e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f7dff2e

Please sign in to comment.