Skip to main content
Watch in WebView: Fix "Share" Function Issue in iOS
Updated over a week ago

Due to the default WKWebView behavior, the "Share" function in iOS might not work properly.

In Order to fix it, follow up the following steps:

  • Add WKUserContentController to WKWebView configuration:

 webView.configuration.userContentController.add(self, name: "openLink")

  • Implement WKScriptMessageHandler delegate method for ViewController

func userContentController(_ userContentController: WKUserContentController, 

didReceive message: WKScriptMessage) {

if message.name == "openLink", let urlString = message.body as? String,let url = URL(string: urlString) {

UIApplication.shared.open(url)

}

}

Did this answer your question?