moo
moo

Reputation: 115

xcode webview error not working

This web view failed error showing the alert popup even when it is loading the website. I believe I need to delay this method in order for it to work.What will be the best method for doing this?

- (void)webView:(UIWebView *)webViewfail didFailLoadWithError:(NSError *)error 
{
    if([webViewfail isEqual:webview]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:@"Check your Internet connection before refreshing."
                                                   delegate:webview
                                          cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}

Here is how I am loading the website

- (void)viewDidLoad
{
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL    URLWithString:@"http://www.blabla.com"]]];
}

Upvotes: 1

Views: 1429

Answers (1)

Will Reeves
Will Reeves

Reputation: 53

The problem is most likely an error -999 which generally happens when something from the webpage does not load correctly or a user tries to navigate back while the page is still loading. After some research here's what I found and used to keep the NetworkAlert from poping up every time but still popping up when there is no network.

-(void)webView:(UIWebView *)webBlog didFailLoadWithError:(NSError *)error{

if ([error code] != -999) {
    NSLog(@"Could not load the dumb webPage");
    //show error alert, etc.
    [self showNoNetworkAlert];
   }else{

NSLog(@"Could not load the dumb web page...just might blame user!");
    }
}

- (void) showNoNetworkAlert{
UIAlertView *baseAlert = [[UIAlertView alloc]
                          initWithTitle:@"No Network"     message:@"A network connection is required.  Please verify your network settings and try again."
                          delegate:nil cancelButtonTitle:nil
                          otherButtonTitles:@"Dismiss", nil];
[baseAlert show];
}

Hope this helps someone...

Upvotes: 1

Related Questions