views:

319

answers:

2

Hey Guys,

I have a UIWebView within my application which I'm using to provide web browsing functionality.

I have a button on my toolbar which calls

-(void)stopLoading;

on the UIWebView. The problem with this is that when this method is sent to the web view, the delegate receives the

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;

message. The error accompanying this call is: Operation could not be completed. (NSURLErrorDomain error -999.)

I also use the didFailLoad message to tell if the page actually failed to load - and in that case, I display an html formatted message to user to communicate this failure to them.

So the problem is that if the user hits the stop button, the error page is shown instead of just showing whatever parts of the page loaded before being stopped.

I had hoped that NSError.h contained an enum of error codes that I could compare against - but it seems like I'll have to make my own based on my observations of the error codes that come out in my logs - which is less than ideal, since they could change in the future...

Any suggestions would be great, thanks.

A: 

The best way I could find to solve this was to create an enum using the error codes given by the webView.

It doesn't look like they're going to change, but if they do, well - ho hum.

So now, in my failed-to-load method I simply compare the error code from the error object with my enum, and I can see what happened - looks kinda like this:

typedef enum {  
    BrowserErrorHostNotFound = -1003,
    BrowserErrorOperationNotCompleted = -999,
    BrowserErrorNoInternetConnection = -1009
} BrowserErrorCode;
Jasarien
A: 

Those error codes are defined in NSURLError.h, in the Foundation.framework

snowytree