1

このケース (NSLog(@"A gateway to the host server is down."); は、何らかの理由で常に実行されています。

舞台裏で Apple Reachability クラスを使用しています。他のホストを挿入しようとしましたが、うまくいきません。助けてください。

前もって感謝します。

ここにコードがあります

@implementation ConnectionManager
@synthesize internetActive, hostActive;

-(id)init {
self = [super init];
if(self) {

}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:@"NetworkReachabilityChangedNotification" object:nil];

internetReachable = [Reachability reachabilityForInternetConnection];
[internetReachable startNotifier];

hostReachable = [Reachability reachabilityWithHostName:@"www.google.com"];
[hostReachable startNotifier];



return self;
}

- (void) checkNetworkStatus:(NSNotification *)notice
{
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)

{
    case NotReachable:
    {
        NSLog(@"The internet is down.");
        self.internetActive = NO;

        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;

        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;

    }
}

}
4

1 に答える 1

0

同じエラーを表示することについて言及していないのでinternetReachable、インターネットに接続でき、その部分が正常に機能していると想定しています。パーツについては、次のhostReachableように変更してみてください。

変化する

[Reachability reachabilityWithHostName:@"www.google.com"]; 

[Reachability reachabilityWithHostName:@"http://www.google.com"];
于 2013-02-15T00:15:30.190 に答える