您需要實施的其他回調得到這個權利(雨燕3.1):
// Gets called if webView cant handle URL
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
guard let failingUrlStr = (error as NSError).userInfo["NSErrorFailingURLStringKey"] as? String else { return }
let failingUrl = URL(string: failingUrlStr)!
switch failingUrl {
// Needed to open Facebook
case _ where failingUrlStr.startsWith("fb:"):
if #available(iOS 10.0, *) {
UIApplication.shared.open(failingUrl, options: [:], completionHandler: nil)
return
} // Else: Do nothing, iOS 9 and earlier will handle this
// Needed to open Mail-app
case _ where failingUrlStr.startsWith("mailto:"):
if UIApplication.shared.canOpenURL(failingUrl) {
UIApplication.shared.openURL(failingUrl)
return
}
// Needed to open Appstore-App
case _ where failingUrlStr.startsWith("itmss://itunes.apple.com/"):
if UIApplication.shared.canOpenURL(failingUrl) {
UIApplication.shared.openURL(failingUrl)
return
}
default: break
}
}
現在的Facebook,郵件,蘋果商店,...得到直接從您的應用程序稱爲無需打開Safari
你不能這樣做。如果這個功能對你來說很重要,那麼這就是現在堅持使用UIWebView的原因 - 以及向Apple提交增強請求的原因。 UIWebView可以做WKWebView無法做到的事情。 – matt 2014-10-22 19:07:04