4 Replies Latest reply: Mar 24, 2009 3:35 AM by Jminijmini
JavaJini Level 1 Level 1 (0 points)
I am using UIWebView to render a GPS map on the iPhone. When I load it with the following code:

[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];

I get an NSURLErrorDomain error -999. The same code works fine with other URLs like www.apple.com and www.intel.com. It doesnt seem to be a redirect issue; I tested it by creating a tinyurl for www.apple.com and it worked fine with my code. Where would I find the documentation for error code -999 or how to fix the error?

Mac OS X (10.5.4)
  • noam_dev Level 1 Level 1 (0 points)
    I get the same error occasionally within WebViews and I have no idea why this is occurring.
  • Pumbaa Level 1 Level 1 (15 points)
    <conjecture> Error -999 can be safely ignored in a UIWebView</conjecture>

    This is a dirty workaround that makes UIWebView work as it should

    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    NSLog(@"Error %i", error.code);
    if (error.code == NSURLErrorCancelled) return; // this is Error -999
    // error handling for "real" errors here

    I'm still not sure what causes the error, but it might have something to do with iFrames or JavaScript requests. It's definitely not a redirect issue.
  • Jminijmini Level 1 Level 1 (0 points)
    Like JavaJini, I put a similar code in the IBAction of a button.

    -(IBAction)goButtonIsTouched:(id)sender {
    [theWebView stopLoading];

    NSURLRequest *URLReq = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]];
    [theWebView loadRequest:URLReq];
    [theWebView reload];

    The first time a click on the button, it is working fine, and the second time it is not.
    Maybe something has to be done before calling loadRequest a second time.

    The workaround proposed by Pumbaa do not display the error, but the page is still not reloading (the error still happend).
  • Jminijmini Level 1 Level 1 (0 points)
    NSURLErrorDomain error -999 == NSURLErrorCancelled.

    The explanation:
    "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 conjecture from pumba is correct, you do not need to display it.

    The code I have given before trigger a such Error because I did a loadRequest and a reload (the reload line is not necessary).
    --> making a stopLoading before the new request is a good idea.

    A other way to trigger such errors is to click very quickly on 2 links. The first request is canceled (--> Trigger the -999 error).

    If you want to avoid such error, you can add some overhead code in order to assure that when something is loading nothing else can be loaded. But as pumba said it is not a big deal.