I am working on a wrapper for WKWebView
and want to make sure I handle possible errors.
How can I make WKNavigationDelegate
's method
func webView(_: WKWebView, didFail _: WKNavigation!, withError error: Error)
called?
The first thing I tried was to call webView.load(request)
with invalid url. As a result, func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)
only was called -- not what I wanted.
The second thing I tried was to call webView.loadHTMLString(html, baseURL: nil)
with malformed html. Nevertheless, webView displayed without throwing an error.
I am working on a wrapper for WKWebView
and want to make sure I handle possible errors.
How can I make WKNavigationDelegate
's method
func webView(_: WKWebView, didFail _: WKNavigation!, withError error: Error)
called?
The first thing I tried was to call webView.load(request)
with invalid url. As a result, func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)
only was called -- not what I wanted.
The second thing I tried was to call webView.loadHTMLString(html, baseURL: nil)
with malformed html. Nevertheless, webView displayed without throwing an error.
1 Answer
Reset to default 1You can load a valid URL and stop loading manually as soon as the navigation is committed.
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
print("didCommit called - stopping navigation now.")
webView.stopLoading()
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("didFail navigation called")
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744203849a4563006.html
didFailProvisionalNavigation
will be called if there is an error in the early navigation process Reference. I would try simulating a network issue or maybe a timeout. – tomerpacific Commented Mar 25 at 10:52