While checking for reachability(network availability) of an iPAD 3 WiFi+Cellular, I ran into across a weird issue that happened in the below mentioned scenario.
- To check network availability I have used Apple sample code for reachability.
- The following code was implemented to check availability of WiFi or WWAN.
`
- (BOOL)networkCheck
{
Reachability *wifiReach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
switch (netStatus)
{
case NotReachable:
{
NSLog(@"%@",@"NETWORKCHECK: Not Connected");
return false;
break;
}
case ReachableViaWiFi:
{
NSLog(@"%@",@"NETWORKCHECK: Connected Via WiFi");
return true;
break;
}
case ReachableViaWWAN:
{
NSLog(@"%@",@"NETWORKCHECK: Connected Via WWAN");
return true;
break;
}
}
return false;
}
`
- In a scenario when there was NO SIM in the iPAD & also there was No-WiFi connection, the above method executes ReachableViaWWAN case, which seems totally incorrect as there is NO SIM or any other WWAN network available.
To Overcome this issue a workaround (or should I say a hack) was suggested & implemented as follows: Send a request to a reliable host & check for its response.
case ReachableViaWWAN:
{
NSLog(@"%@",@"NETWORKCHECK: Connected Via WWAN");
NSData *responseData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.google.com"]] returningResponse:nil error:nil];
if (responseData != nil)
{
return true;
break;
}
else
{
return false;
break;
}
}
I have a couple of queries:
- This may sound offbeat, but is it something wrong with the hardware or iOS that it's ReachableViaWWAN even when NO SIM is present in the device?
- Is there a better solution (than the workaround mentioned above) for the problem?