My code for checking for an Internet connection, I discovered yesterday on an airplane, is excruciatingly slow. I am using the technique in many older SO answers of checking an NSUURL, however, it literally took fifteen seconds or more to return FALSE when on an airplane with no connectivity making the app essentially unusable.
Is there a dependable asynchronous method that would do this? People recommend Tony Million's reachability class in older answers but it seems very complicated and Apple is apparently rejecting some apps using it. Would appreciate it if someone could suggest the fastest, reliable way to check Internet connection in 2017. Thank you.
- (BOOL)connected
{
NSURL *scriptUrl = [NSURL URLWithString:@"https://www.google.com"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data) {
NSLog(@"Device is connected to the internet");
return TRUE;
}
else {
NSLog(@"Device is not connected to the internet");
return FALSE;
}
}