Showing posts with label ping server if it is reachable. Show all posts
Showing posts with label ping server if it is reachable. Show all posts

Sunday, March 25, 2012

To ping the server to determine if it is reachable

Here is the method to ping if the server is reachable.


- (BOOL)canPingServer {
    
    NSString *serverAddress = urlField.text;
    
    NSLog(@"ping domain: %@", serverAddress);
    
    Reachability* reachability = [[Reachability reachabilityWithHostName: serverAddress] retain];
    NetworkStatus netStatus = [reachability currentReachabilityStatus];
    
    if ((netStatus == ReachableViaWWAN) || (netStatus == ReachableViaWiFi)) 
            return YES;
    else 
            return NO;
    
}