Skip to content

Instantly share code, notes, and snippets.

@hamsternik
Created December 15, 2016 19:59
Show Gist options
  • Save hamsternik/3ccd3adae7a852080a62e03511b48da3 to your computer and use it in GitHub Desktop.
Save hamsternik/3ccd3adae7a852080a62e03511b48da3 to your computer and use it in GitHub Desktop.
- (BOOL)isConnectedToInternet
{
CFNetDiagnosticRef diag = CFNetDiagnosticCreateWithURL(kCFAllocatorDefault, (__bridge CFURLRef)[NSURL URLWithString:@"www.apple.com"]);
CFNetDiagnosticStatus status = CFNetDiagnosticCopyNetworkStatusPassively(diag, NULL);
CFRelease(diag);
if (status == kCFNetDiagnosticConnectionUp) {
return YES;
} else {
NSLog(@"No Internet Connection");
return NO;
}
}
@hamsternik
Copy link
Author

hamsternik commented Dec 15, 2016

If you will use this method to check internet connection and your device has been connected to the Internet by 3G/LTE, the result of the CFNetDiagnosticCopyNetworkStatusPassively will be -66557L, means "kCFNetDiagnosticConnectionDown".
This bug was confirmed by Apple with the ID #12443370.

So, as I understood, the best way to check the internet connection is just using such *NetworkReachibility framework, but it's so terrible: if you wanna just check this so easy issue, you have to download GitHub repo's with custom implementation, using cocoa pods or submodules, or, more 'optimize' way - just download the Reachability{.h/.m} files from the Apple example and import them into your project.

Good job, Apple.

ps. this small post I wrote after such quick comprehension of the Android and iOS abilities to check internet connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment