Search code examples
iphoneiosxcodereachabilityinternet-connection

Check for Internet in UIWebView App on jQuery .click()


I use this code to check for internet when the app opens for the first time:

//No Internet Connection error code
-(void)webView:(UIWebView *)webVIEW didFailLoadWithError:(NSError *)error {
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection!" message:@"In order to use this app you need an active Internet connection!" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
   [alert show];  
}

//Close app from Alert View
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
exit(0);
}

I have a UIWebView app that has a jQuery .click() function. Is there a way to check for Internet again once the user clicks that button?


Solution

  • Take a look at Apple's sample code. The Reachability project shows how to detect a connection

    http://developer.apple.com/iphone/library/samplecode/Reachability/index.html