Custom scheme URL 在WKWebView中默认是不支持的 (但Safari可以).

我们可以通过NSError来进行一些处理从而使得程序可以正常跳转:

func webView(webView: WKWebView, didFailNavigation navigation: WKNavigation!, withError error: NSError) {
    handleError(error)
}

func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
    handleError(error)
}

func handleError(error: NSError) {
    if let failingUrl = error.userInfo["NSErrorFailingURLStringKey"] as? String {
        if let url = NSURL(string: failingUrl) {
            let didOpen = UIApplication.sharedApplication().openURL(url)
            if didOpen {
                print("openURL succeeded")
                return
            }
        }
    }
}

Note: 在iOS9中,如果你要想使用canOpenURL, 你必须添加URL schemes到Info.plist中的白名单, 否则一样跳转不了...

相关文章:

  • 2022-01-24
  • 2022-12-23
  • 2021-10-04
  • 2021-07-15
  • 2022-02-07
  • 2021-09-21
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2021-08-18
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案