Created
July 17, 2010 01:25
-
-
Save robin/479148 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
#import <SystemConfiguration/SCNetworkReachability.h> | |
#define ReachableViaWiFiNetwork 2 | |
#define ReachableDirectWWAN (1 << 18) | |
// fast wi-fi connection | |
+(BOOL)hasActiveWiFiConnection | |
{ | |
SCNetworkReachabilityFlags flags; | |
SCNetworkReachabilityRef reachabilityRef; | |
BOOL gotFlags; | |
reachabilityRef = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(),[@"www.apple.com" UTF8String]); | |
gotFlags = SCNetworkReachabilityGetFlags(reachabilityRef, &flags); | |
CFRelease(reachabilityRef); | |
if (!gotFlags) | |
{ | |
return NO; | |
} | |
if( flags & ReachableDirectWWAN ) | |
{ | |
return NO; | |
} | |
if( flags & ReachableViaWiFiNetwork ) | |
{ | |
return YES; | |
} | |
return NO; | |
} | |
// any type of internet connection (edge, 3g, wi-fi) | |
+(BOOL)hasNetworkConnection; | |
{ | |
SCNetworkReachabilityFlags flags; | |
SCNetworkReachabilityRef reachabilityRef; | |
BOOL gotFlags; | |
reachabilityRef = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.apple.com" UTF8String]); | |
gotFlags = SCNetworkReachabilityGetFlags(reachabilityRef, &flags); | |
CFRelease(reachabilityRef); | |
if (!gotFlags || (flags == 0) ) | |
{ | |
return NO; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment