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;
            return NO;

No comments:

Post a Comment