I want to check connection to a local wifi with bonjour using [Reachability reachabilityForLocalWifi]
but it is now deprecated in iOS 10. Apple suggested to use [Reachability reachabilityWithAddress:]
but it still returns "not reachable" even when i'm connected to a local wifi.
update:
Here is my code using reachabilityWithAddress
which always returns "not reachable" for local wifi.
+(BOOL)checkWifiConnectionIfOn{
BOOL isOn;
struct sockaddr_in localWifiAddress;
bzero(&localWifiAddress, sizeof(localWifiAddress));
localWifiAddress.sin_len = sizeof(localWifiAddress);
localWifiAddress.sin_family = AF_INET;
// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0.
localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
Reachability* returnValue = [Reachability reachabilityWithAddress:(struct sockaddr_in *) &localWifiAddress];
if (returnValue != NULL && [returnValue currentReachabilityStatus] != NotReachable) //Reachable
{
//
isOn = YES;
}
else{ // Not Reachable
NSString *log = [NSString stringWithFormat:@"WifiController checkWifiConnectionIfOn Wifi OFF"];
[Logger writeDeviceLog:log logType:ERROR_LOG];
isOn = NO;
}
return isOn;
}