Last active
December 18, 2015 13:19
-
-
Save Geri-Borbas/5789393 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
static void reachabilityCallback(SCNetworkReachabilityRef reachabilityRef, SCNetworkReachabilityFlags flags, void* info) | |
{ | |
RCViewController *viewController = (__bridge RCViewController*)info; //Cast context object. | |
[viewController showReachabilityFlags:flags]; //Show. | |
//Tear down reachability. | |
SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetMain(), kCFRunLoopDefaultMode); | |
CFRelease(reachabilityRef); | |
} | |
-(void)reach:(NSString*) hostName | |
{ | |
//Create with context. | |
SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); | |
SCNetworkReachabilityContext context = {0, (__bridge void*)self, nil, nil, nil}; | |
if (NO) //The synchronous way, works well with IP addresses as hostname. | |
{ | |
//Get flags. | |
SCNetworkReachabilityFlags flags; | |
SCNetworkReachabilityGetFlags(reachabilityRef, &flags); | |
[self showReachabilityFlags:flags]; //Show. | |
} | |
else //The asynchronous way, NOT WORKS (!!!) with IP addresses as hostname. | |
{ | |
//Set callback, then register. | |
SCNetworkReachabilitySetCallback(reachabilityRef, reachabilityCallback, &context); | |
SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetMain(), kCFRunLoopDefaultMode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment