【发布时间】:2016-09-27 08:35:57
【问题描述】:
在我的应用程序中,我正在从 UIWebView 迁移到 WKWebView ,如何为 WKWebView 重写这些函数?
func webViewDidStartLoad(webView: UIWebView){}
func webViewDidFinishLoad(webView: UIWebView){}
和
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
print("webview asking for permission to start loading")
if navigationType == .LinkActivated && !(request.URL?.absoluteString.hasPrefix("http://www.myWebSite.com/exemlpe"))!{
UIApplication.sharedApplication().openURL(request.URL!)
print(request.URL?.absoluteString)
return false
}
print(request.URL?.absoluteString)
lastUrl = (request.URL?.absoluteString)!
return true
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
print("webview did fail load with error: \(error)")
let testHTML = NSBundle.mainBundle().pathForResource("back-error-bottom", ofType: "jpg")
let baseUrl = NSURL(fileURLWithPath: testHTML!)
let htmlString:String! = "myErrorinHTML"
self.webView.loadHTMLString(htmlString, baseURL: baseUrl)
}
【问题讨论】:
-
听起来你应该看看
navigationDelegate的WKWebView。
标签: ios swift uiwebview wkwebview