SCNetworkReachability only works for domain names?
Given iOS's SCNetworkReachability API configured like this:
SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName(N开发者_C百科ULL, "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?
Try using SCNetworkReachabilityCreateWithAddress instead of SCNetworkReachabilityCreateWithName.
Use eppz!reachability
that works well with IP addresses, too. Simple usage like:
// Get status on-demand.
[EPPZReachability reachHost:@"eppz.eu"
completition:^(EPPZReachability *reachability)
{
if (reachability.reachable) [self postSomething];
}];
It is true. It won't work nor with SCNetworkReachabilityCreateWithAddress
(It actually works on future reachability condition changes, but the first callback never get called).
If you design needs only on-demand reachability check, consider using SCNetworkReachabilityGetFlags
.
A bit more at: Why asynchronous reachability with IP address doesn’t work? and Reachability with blocks for everyday use
精彩评论