How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS

IphoneIphone Sdk-3.0

Iphone Problem Overview


I am trying to update my iPhone app to work with OS 3.0. I have a UIWebView that shows a page fine. But when I click a link it calls my delegate for didFailLoadWithError and the error is Operation could not be completed. (NSURLErrorDomain error -999.) I verified this is still working with OS 2.2.1, so it is something changed in 3.0.

Any ideas?

Iphone Solutions


Solution 1 - Iphone

I was able to find the answer here.

This thread contained this description for this error: This error may occur if an another request is made before the previous request of WebView is completed...

I worked around this by ignoring this error and letting the webview continue to load.

if ([error code] != NSURLErrorCancelled) {
//show error alert, etc.
}

Solution 2 - Iphone

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."

For my situation (and probably yours) this can be ignored:

if([error code] == NSURLErrorCancelled) return; // Ignore this error

Solution 3 - Iphone

The above TWO replies was CORRECT> Just do a return if the loading request causes cancellation.

Also I want to point out that, people do NOT forget to put an NSLog inside your didFailLoadWithError method, this can prevent losing a lot of time by spotting the issue right on!

So here is the final solution with all I mentioned above:

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"ERROR : %@",error); //Get informed of the error FIRST
    if([error code] == NSURLErrorCancelled) 
        return;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondp.View Question on Stackoverflow
Solution 1 - Iphonedp.View Answer on Stackoverflow
Solution 2 - IphoneBadPirateView Answer on Stackoverflow
Solution 3 - IphoneKhayrattee WasseemView Answer on Stackoverflow