Monish Kumar Monish Kumar - 2 months ago 10x
Objective-C Question

How to find the 404 error cause, when I am using a webview based application and the server fails in iphone sdk

I am implementing a webview based application, in that I need to find out a way when the 404 error occurred.

Anyone's help will be much appreciated.

Thanks to all,


Here you just need to check the status of the request when it finishes or fails in webview delegate method.`

     - (void)webViewDidFinishLoad:(UIWebView *)webView
    int status = [[[webView request] valueForHTTPHeaderField:@"Status"] intValue];
    if (status == 404) {


If this doesn't help you out. Check this one. Create an NSURLRequest with the URL you want to load. Then make the connection using NSURLConnection.

NSURLConnection has a delegate method

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

which will give the the response from the server. Please note that if you are making the connection over HTTP, the response will actually be of class NSHTTPURLResponse. The NSHTTPURLResponse can be used to get the status using the following instance method

- (NSInteger)statusCode

Then check if status = 404 or not and if yes then show your alert view. In this way you will be able to show the html page and the alert view both.