Created
July 18, 2009 11:10
-
-
Save soffes/149508 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)isConnectedToNetwork { | |
// Recover reachability flags | |
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorSystemDefault, [@"twitter.com" UTF8String]); | |
SCNetworkReachabilityFlags flags; | |
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(reachability, &flags); | |
CFRelease(reachability); | |
if (!didRetrieveFlags) { | |
NSLog(@"Error. Could not recover network reachability flags."); | |
return NO; | |
} | |
BOOL isReachable = flags & kSCNetworkFlagsReachable; | |
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; | |
return (isReachable && !needsConnection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment