Reachability not working as expected

Adam Waite picture Adam Waite · Jul 1, 2012 · Viewed 9.1k times · Source

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?

Answer

Omar Abdelhafith picture Omar Abdelhafith · Jul 1, 2012

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];