Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): share message handler between webview and bridge #3875

Merged
merged 1 commit into from
Nov 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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