Search code examples
iphonereachability

How to find server is reachable with Reachability code in iPhone?



I have client server say "http://abc.com" and i want to check whether this server responding or not.
How to check this with Reachability code from apple?
As i see that code but not able to get where to write my client's url to check this.
Please suggest me.


Solution

  • Here's a synchronous example. You'll probably want to do this asynchronously, but this will get you through for a quick check.

    Reachability *netReach = [Reachability reachabilityWithHostName:@"host.name"];
    //return [netReach currentReachabilityStatus];
    NetworkStatus netStatus = [netReach currentReachabilityStatus];
    if (netStatus==ReachableViaWiFi) {
        [ViewManager showStatus:@"Reachable (WiFi)!"];
    } else if(netStatus==ReachableViaWWAN) {
        [ViewManager showStatus:@"Reachable (WWAN)!"];
    } else {
        [ViewManager showStatus:@"Not reachable, aww :-("];
    }
    

    When using reachabilityWithHostName you have to remember that this is just the host name, there should be no http:// prefix or the like.