我想在我的应用程序中检查互联网连接。在这样做时,我使用以下代码。internetStatus 和主机状态有什么区别。我应该使用哪个来检查 ipad 是否有互联网连接。
-(void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
//NSLog(@"The internet is down.");
//self.internetActive = NO;
//NSLog(@"A gateway to the host server is down.");
//self.hostActive = NO;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed"
message:@"No internet connection"
delegate:nil
cancelButtonTitle:@"Exit"
otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];
[alert release];
break;
}
case ReachableViaWiFi:
{
//NSLog(@"The internet is working via WIFI.");
//self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
//NSLog(@"The internet is working via WWAN.");
//self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
//NSLog(@"A gateway to the host server is down.");
//self.hostActive = NO;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed"
message:@"No internet connection"
delegate:nil
cancelButtonTitle:@"Exit"
otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];
[alert release];
break;
}
case ReachableViaWiFi:
{
//NSLog(@"A gateway to the host server is working via WIFI.");
//self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
//NSLog(@"A gateway to the host server is working via WWAN.");
//self.hostActive = YES;
break;
}
}
}