Ignoring NSURLErrorDomain error -999 does not work in UIWebView

随声附和 提交于 2019-11-30 14:31:51

From Apple docs:

NSURLErrorCancelled (-999)

"Returned when an asynchronous load is canceled. A Web Kit framework delegate will receive this error when it performs a cancel operation on a loading resource. Note that an NSURLConnection or NSURLDownload delegate will not receive this error if the download is canceled."

So, the most likely case for this to happen is for you to load a request and then another one (or the same one), before the first one is completed. This can happen. e.g., if you call loadRequest (or loadHTMLString) in a method like viewDidAppear: that can be called multiple times. This has also been reported to happen if you quickly tap 2 links in the UIWebView.

So, the general suggestion is to review how and where you call loadRequest (or loadHTMLString), and possibly provide some code.

In order to troubleshoot this, I would suggest to add the following traces to your web view delegate:

- (void)webViewDidStartLoad:(UIWebView *)webView {
      NSLog(@"Starting to download request: %@", [webView.request.URL absoluteString]);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
      NSLog(@"Finished downloading request: %@", [webView.request.URL absoluteString]);
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

    if ([error code] == NSURLErrorCancelled)
      NSLog(@"Canceled request: %@", [webView.request.URL absoluteString]);
}

If you inspect the output, you should see more clearly what is going on. If you paste the output, we could try and help you further.

Most of the time when working with NSURLConnection or UIWebView, this error is due to a timeout. Might really not be your code, but your connectivity.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!