en mi aplicación estoy migrando de UIWebView a WKWebView, ¿cómo puedo reescribir estas funciones para WKWebView?
func webViewDidStartLoad(webView: UIWebView){}
func webViewDidFinishLoad(webView: UIWebView){}
y
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
deWKWebView
.Respuestas:
UIWebView => Equivalente a WKWebView
Acerca de
shouldStartLoadWithRequest
puedes escribir:Y para el
didFailLoadWithError
:fuente
WKNavigationDelegate
(noWKUIDelegate
).Aquí están los métodos de Objective-C para la migración
1) shouldStartLoadWithRequest -> decidePolicyForNavigationAction
Recuerda llamar al
decisionHandler
2) webViewDidStartLoad -> didStartProvisionalNavigation
3) webViewDidFinishLoad -> didFinishNavigation
4) didFailLoadWithError -> didFailNavigation
fuente
WKNavigationTypeLinkActivated
lugar deUIWebViewNavigationTypeLinkClicked
?Migración de UIWebView a WKWebView, Swift 4 :
Equivalente de
shouldStartLoadWithRequest
:Equivalente de
webViewDidStartLoad
:Equivalente de
didFailLoadWithError
:Equivalente de
webViewDidFinishLoad
:fuente