Search code examples
iosiphonenetwork-programming

SCNetworkReachability only works for domain names?


Given iOS's SCNetworkReachability API configured like this:

SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName(NULL, "example.com");
SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL};
SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context);
SCNetworkReachabilitySetDispatchQueue(reachabilityRef, dispatch_queue);

It works nice if I configure it with a domain name as in the example above. However, if I configure it with an IP address the callback is never called.

Anyone can confirm that this is the expected behavior of the SCNetworkReachability API? If so, any clues why?


Solution

  • Try using SCNetworkReachabilityCreateWithAddress instead of SCNetworkReachabilityCreateWithName.