no meu aplicativo estou migrando de UIWebView para WKWebView, como posso reescrever essas funções para WKWebView?
func webViewDidStartLoad(webView: UIWebView){}
func webViewDidFinishLoad(webView: UIWebView){}
e
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
doWKWebView
.Respostas:
UIWebView => WKWebView Equivalent
Sobre
shouldStartLoadWithRequest
você pode escrever:E para o
didFailLoadWithError
:fonte
WKNavigationDelegate
(nãoWKUIDelegate
).Aqui estão os métodos Objective-C para a migração
1) shouldStartLoadWithRequest -> decidePolicyForNavigationAction
Lembre-se de ligar para o
decisionHandler
2) webViewDidStartLoad -> didStartProvisionalNavigation
3) webViewDidFinishLoad -> didFinishNavigation
4) didFailLoadWithError -> didFailNavigation
fonte
WKNavigationTypeLinkActivated
vez deUIWebViewNavigationTypeLinkClicked
?Migrando UIWebView para WKWebView, Swift 4 :
Equivalente a
shouldStartLoadWithRequest
:Equivalente a
webViewDidStartLoad
:Equivalente a
didFailLoadWithError
:Equivalente a
webViewDidFinishLoad
:fonte