Search code examples
objective-ciosreachability

Reachability not working as expected


Downloaded Reachability from Apple, using this method to check for an active connection:

-(BOOL)isReachable{

    Reachability *r = [Reachability reachabilityWithHostName:@"http://www.google.com"];

    if(NotReachable == [r currentReachabilityStatus]) {
        NSLog(@"Not Reachable");
        return NO;
    }

    NSLog(@"Reachable");
    return YES;  

}

Returns NO every single time despite being connected? Can't figure out why...

Any ideas? Thanks.

On a side note, can anyone recommend a good clean Reachability singleton class?


Solution

  • EDITED: you should remove the protocol, http from your reachabilityWithHostName call, so updated it to

     Reachability *reachability = [Reachability reachabilityWithHostname:@"www.google.com"];
     NetworkStatus netStatus = [reachability currentReachabilityStatus];