Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用可达性dosen'检查网络连接;无法使用子域名_Iphone_Objective C - Fatal编程技术网

Iphone 使用可达性dosen'检查网络连接;无法使用子域名

Iphone 使用可达性dosen'检查网络连接;无法使用子域名,iphone,objective-c,Iphone,Objective C,要在我的iPhone应用程序中检查网络连接,我使用以下代码: _hostReachable = [[Reachability reachabilityWithHostName: @"https://abc1.abc.com"] retain]; [_hostReachable startNotifier]; 并检查状态 NetworkStatus status = [_hostReachable currentReachabilityStatus]; 我确实测试过了“https://mail

要在我的iPhone应用程序中检查网络连接,我使用以下代码:

_hostReachable = [[Reachability reachabilityWithHostName: @"https://abc1.abc.com"] retain];
[_hostReachable startNotifier];
并检查状态

NetworkStatus status = [_hostReachable currentReachabilityStatus];
我确实测试过了“https://mail.google.com“或”http://translate.google.com并且该状态总是返回NotReachable与该子域名,但与http://google.com“没关系


可达性不适用于子域名吗?请帮帮我,谢谢

刚刚用我的应用程序进行了测试-可以通过子域访问的主机似乎正在工作


我注意到您包括了协议
http://
https://
。也许这就是问题所在。试着只使用
abc1.abc.com

以下代码用于检查网络连接

 -(void) viewWillAppear:(BOOL)animated
    {
        // check for internet connection
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:)  name:kReachabilityChangedNotification object:nil];
        internetReachable = [[Reachability reachabilityForInternetConnection] retain];         
        [internetReachable startNotifier];         

        // check if a pathway to a random host exists        
        hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"]  retain];
         [hostReachable startNotifier];         
        // now patiently wait for the notification 
    }
在appDelegate中创建了一个方法

- (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;
                 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;
            }
        }
    }