私は私のアプリでこれを使用
:
// Check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [Reachability reachabilityForInternetConnection];
[internetReachable startNotifier];
// Check if a pathway to a random host exists
hostReachable = [Reachability reachabilityWithHostName: @"www.apple.com"];
[hostReachable startNotifier];
と:私は
- (void) checkNetworkStatus:(NSNotification *)notice
{
// Called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
// Case: No internet
case NotReachable:
{
internetActive = NO;
// Switch to the NoConnection page
NoConnectionViewController *notConnected = [[NoConnectionViewController alloc] initWithNibName:@"NoConnectionViewController" bundle:[NSBundle mainBundle]];
notConnected.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:notConnected animated:NO];
break;
}
case ReachableViaWiFi:
{
internetActive = YES;
break;
}
case ReachableViaWWAN:
{
internetActive = YES;
break;
}
}
// Check if the host site is online
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
hostActive = NO;
break;
}
case ReachableViaWiFi:
{
hostActive = YES;
break;
}
case ReachableViaWWAN:
{
hostActive = YES;
break;
}
}
}
この種の問題を抱えている私は、人々が通常これを解決せず、Reachabilityを使うのはなぜだろうかと思います。私はそれが無線LANに接続されていて、インターネットが実際に動作していない場合、アプリで何が起こるかを意味します。そして、彼らはこのケースをどのように処理しますか –