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

3

53

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?

Varick answered 21/6, 2009 at 21:5 Comment(3)
details like which page are in the UIWebView (if it's public) and how you setup this view and delegate in code might be useful.Piero
I am on the road now and will get more details added when I get back. It is a public web page. In further digging it looks like it may be related to a page not being fully loaded before the next request is received. I have not had a chance to test that yet. If that proves to be the issue I will update.Varick
I think you need to revisit which is considered the correct answerCumulous
V
121

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.
}
Varick answered 27/6, 2009 at 18:56 Comment(5)
Better to use the constant NSURLErrorCancelled instead of the literal value -999.Hexa
This error may also be a code smell. I got rid of it not by ignoring it, but by moving a load-triggering method call from viewDidAppear (which could trigger multiple times while loading the web view) into viewDidLoad.Prokofiev
Better yet, the uiwebview has a boolean "loading" property that you should check and then explicitly stop the loading operation. However, in my case this seems to be the result of deallocating the webview.Cherisecherish
I got rid of it by forcing to reload the url a few times by putting the request in the delegate method - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error. This helps for Twitter and Facebook annoyancesBluet
Man, I owe you a beerRachelrachele
F
29

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
Friedlander answered 10/11, 2010 at 18:5 Comment(0)
R
12

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;
}
Rhodolite answered 23/4, 2013 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.