Created
December 15, 2016 19:59
-
-
Save hamsternik/3ccd3adae7a852080a62e03511b48da3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.