The method below works very well for checking to see if a user has an internet connection. I would like to check for an internet connection throughout my entire app, and am wondering if there is somewhere I can put it within my App Delegate where it will get called from every view controller.
Is there a way to do this? Doesn't seem to work properly if I put it in my applicationDidFinishLaunching. Any recommendations would be great! Thank you!
NSURL *scriptUrl = [NSURL URLWithString:@"http://www.google.com/m"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data) {
NSLog(@"Device is connected to the internet");
}
else {
NSLog(@"Device is not connected to the internet");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connectivity"
message:@"You must have an internet connection" delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
return;
}