Ios internetStatus和hostStatus之间的差异
我想在我的应用程序中检查internet连接。在执行此操作时,我使用以下代码。 internetStatus和host status的区别是什么。我应该用哪个来检查ipad是否连接了互联网Ios internetStatus和hostStatus之间的差异,ios,ipad,connection,Ios,Ipad,Connection,我想在我的应用程序中检查internet连接。在执行此操作时,我使用以下代码。 internetStatus和host status的区别是什么。我应该用哪个来检查ipad是否连接了互联网 -(void) checkNetworkStatus:(NSNotification *)notice { // called after network status changes NetworkStatus internetStatus = [internetReachable curr
-(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;
}
}
}
internetStatus
或hostStatus
只要实例名称,您就可以使用任何名称作为状态。但具体来说,如果您没有设置主机,那么您可以使用internetStatus
进行互联网访问,如果可以访问或不可以访问,默认情况下,苹果会检查互联网网关或互联网连接的互联网可用性,在这种情况下,我们不知道检查互联网连接的主机名,但是,您可以使用hostStatus
或特定主机的任何实例名称,您可以自己设置随机主机,例如,检查它是否可访问。程序是相似的
基本上,状态取决于主机名,主机名可以是默认的,也可以像这样自己设置
hostReachable = [Reachability reachabilityWithHostName: @"www.google.com"];
[hostReachable startNotifier];
你能告诉我们你用来创建hostReachable和internetReachable的代码吗?无论如何,它们只是变量名。