I'm getting false positives with my Reachability code. I get the UIAlert "No Internet Connection", when the network is available but not activated. Any help is very much appreciated.
//Check for Internet
Reachability* wifiR开发者_StackOverflow社区each = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
switch (netStatus)
{
case NotReachable:
{
NSLog(@"Access Not Available");
break;
}
case ReachableViaWWAN:
{
NSLog(@"Reachable WWAN");
break;
}
case ReachableViaWiFi:
{
NSLog(@"Reachable WiFi");
break;
}
}
if (netStatus==NotReachable){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet Required" message:@"There is no internet connection. Please connect and try again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}else{
//Push Controller
}
Same answer as the previous question.
Reachability sometimes only gives the correct answer after your app, or some previous app, has tried to connect and waited for data. So you might as well just try to get data from your connection, as that may well give you a more correct answer more quickly than asking the Reachability API. Maybe just let the user decide an activity indicator has been spinning long enough.
精彩评论