2
votes

Hi I want to add network error code into my iPhone app, heres what I have got up to now:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The page couldn't load, please check your internet connection and reopen the app." delegate:self
    cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

I have linked the webview in question in interface builder with delegate. It works on simulator quite well, but when I run it on my iPhone I realised a few things. It only works upon opening up the app the first time when theres no internet connection, if you open the app later with no internet connection and it's still in the multitasking bar it doesn't work. It doesn't work if you lose internet connection while using the app and try to load another page, and that leads on to that currently I have only added this code for 1 uiwebview, while I have 4 otherwise if the error does show up, it shows up 4 times. I need to work out a way to link it to all uiwebviews, but it will only show up once if there is no connection.

Thanks for help in advance.

2
Through which method did your app first try to load the web view? viewDidLoad?Di Wu

2 Answers

2
votes

Check out Apple's Reachability sample code.

0
votes

webView didFailLoadWithError: ---- to fire this everytime you come to webview write ur code in the viewWillAppear.... or try something like this in viewWillAppear ... [webView reload];

Njoy.... !