Custom scheme URL 在WKWebView中默認是不支持的
(但Safari能夠).web
咱們能夠經過NSError來進行一些處理從而使得程序能夠正常跳轉:swift
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中的白名單, 不然同樣跳轉不了...url