Tuesday, October 28, 2014

Alternative method to check network connectivity using Reachability

Import Reachability file and create an object of Reachability


[self checkReachability];

-(void)checkReachability {
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(reachabilityChanged:)
                name:kReachabilityChangedNotification object:nil];
    
    reachability = [Reachability reachabilityWithHostName:@"www.google.com"];
    [reachability startNotifier];
}

- (void)reachabilityChanged:(NSNotification* )notification {
    
    Reachability* curReach = [notification object];

    if ([curReach currentReachabilityStatus] == NotReachable{
        NSLog(@"Server not reachable....");
        [self hideOverlay];       
    }
    else {
        NSLog(@"Server reachable ....");
        
    }

}



No comments:

Post a Comment