Skip to content

Instantly share code, notes, and snippets.

@soffes
Created July 18, 2009 11:10
Show Gist options
  • Save soffes/149508 to your computer and use it in GitHub Desktop.
Save soffes/149508 to your computer and use it in GitHub Desktop.
+ (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