UmbalaAZ
UmbalaAZ

Reputation: 165

Check network connection with Reachability dosen't work with sub domain name

To check network connection in my iPhone app, I'm using this code:

_hostReachable = [[Reachability reachabilityWithHostName: @"https://abc1.abc.com"] retain];
[_hostReachable startNotifier];

And check status

NetworkStatus status = [_hostReachable currentReachabilityStatus];

I did test with "https://mail.google.com" or "http://translate.google.com" and the status always return NotReachable with that subdomain names, but with "http://google.com" it's ok.

Dose Reachability not work with sub domain name ? Please help me, thanks !

Upvotes: 0

Views: 689

Answers (2)

Nimit Parekh
Nimit Parekh

Reputation: 16864

Following code is useful for the checking the network connectivity.

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

One method is created into the 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;
            }
        }
    }

Upvotes: 0

Mundi
Mundi

Reputation: 80273

Just tested it with my app - host reachable with subdomains seems to be working.

I noticed that you are including the protocols http:// and https://. Perhaps that is the problem. Try just using abc1.abc.com.

Upvotes: 2

Related Questions