-
-
Save drodriguez/300168 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
// Reachability Objective-C minimal version | |
// I'm new so memory leaks are possible on this code | |
// Extracted from: | |
// http://www.idevapps.com/forum/archive/index.php/t-3329.html | |
// (look for an imported_kelvin's post) | |
// | |
+ (BOOL)networkAvailable{ | |
SCNetworkReachabilityRef netreach; | |
SCNetworkConnectionFlags flags; | |
struct sockaddr_in zero; | |
memset(&zero, 0, sizeof(zero)); | |
zero.sin_len = sizeof(zero); | |
zero.sin_family = AF_INET; | |
netreach = SCNetworkReachabilityCreateWithAddress( kCFAllocatorSystemDefault, (struct sockaddr *) zero ); | |
if (!SCNetworkReachabilityGetFlags( netreach, &flags )) { | |
return FALSE; | |
} | |
CFRelease(netreach); | |
BOOL reachable = !(flags & (kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsTransientConnection)); | |
return reachable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment