Skip to content

Instantly share code, notes, and snippets.

@robin
Created July 17, 2010 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robin/479148 to your computer and use it in GitHub Desktop.
Save robin/479148 to your computer and use it in GitHub Desktop.
#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