ios - How to get webView didFail called - Stack Overflow

I am working on a wrapper for WKWebView and want to make sure I handle possible errors.How can I make

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.

Share Improve this question asked Mar 25 at 10:23 NickNick 3,46310 gold badges60 silver badges111 bronze badges 1
  • 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
Add a comment  | 

1 Answer 1

Reset to default 1

You 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

相关推荐

  • ios - How to get webView didFail called - Stack Overflow

    I am working on a wrapper for WKWebView and want to make sure I handle possible errors.How can I make

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信