Ignoring NSURLErrorDomain error -999 does not work in UIWebView

后端 未结 2 1260
野的像风
野的像风 2021-01-02 19:40

I\'m trying to avoid the problem generated while UIWebView\'s delegate returns an error like that. I have the common workaround (I saw it anywhere in the Intern

相关标签:
2条回答
  • 2021-01-02 20:22

    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.

    0 讨论(0)
  • 2021-01-02 20:44

    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.

    0 讨论(0)
提交回复
热议问题