Ignoring NSURLErrorDomain error -999 does not work in UIWebView

I am trying to avoid a problem while the UIWebView delegate returns this error. I have a workaround (I saw it anywhere on the Internet) in my delegate implementation

 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { if ([error code] == NSURLErrorCancelled) return; } 

The problem is that this does not always work. Sometimes it loads web pages, another time it downloads parts of a web page (heading, part of text ...) and doesn’t load anything several times.

Is there any other solution? Is there any open source implementation of the browser that works correctly?

+6
source share
2 answers

From Apple docs:

NSURLErrorCancelled (-999)

"Returned when the asynchronous download is canceled. The Web Kit framework divider will receive this error when performing the undo operation on the boot resource. Note that the NSURLConnection or NSURLDownload delegate will not receive this error if the download is canceled."

So, the most likely case for this is to load the request, and then another (or the same one), before the first one is completed. It can happen. for example, if you call loadRequest (or loadHTMLString ) in a method of type viewDidAppear: which can be called several times. This is also reported if you quickly touch 2 links in UIWebView .

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

To fix this problem, I would suggest adding 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 check the output, you should see more clearly what is happening. If you insert a result, we can try and help you.

+10
source

In most cases, when working with NSURLConnection or UIWebView, this error occurs due to a timeout. Perhaps this is not your code, but your connection.

+2
source

All Articles