iOS network reachability - doesn't seem to be working
Asked Answered
C

2

6

I'm following How to check for an active Internet connection on iOS or OSX? and http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html to test for connectivity, but am running into some pretty basic issues.

For example, I'm running a .NET API off of another machine and then trying to connect to it via my mac mini.

1) When IIS is running, everything is working like it should, I was excited that I got this working!

2) I can shut off IIS completely (obviously, host is unreachable) but my reachabilityWithHostName is still reporting that the host is reachable.

Any ideas?

Caster answered 3/5, 2011 at 19:13 Comment(0)
K
4

See the SCNetworkReachability Reference.

The SCNetworkReachability programming interface allows an application to determine the status of a system's current network configuration and the reachability of a target host. A remote host is considered reachable when a data packet, sent by an application into the network stack, can leave the local device. Reachability does not guarantee that the data packet will actually be received by the host.

Turning IIS on and off is just preventing your server from receiving web request such as ftp/http and does not stop the device from successfully sending a data packet out.

Krystenkrystin answered 3/5, 2011 at 20:7 Comment(2)
Ah - thank you, that makes sense. How would I actually test if my web service is up then??Caster
Do a GET or HEAD request and look for a 200 - OK message using NSURLConnection or ASIHttpRequestKrystenkrystin
G
4

A while ago I used this answer to solve my problem. I found a better solution and I am posting it here for others who may find it helpful.

There is a nice sample code provided by Apple.

Download the sample code here

Include the Reachability.h and Reachability.m files in your project. Take a look at ReachabilityAppDelegate.m to see an example on how to determine host reachability, reachability by WiFi, by WWAN etc. For a very simply check of network reachability, you can do something like this

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];   
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];    
if (networkStatus == NotReachable) {        
    NSLog(@"There IS NO internet connection");        
} else {        

     NSLog(@"There IS internet connection");        


    }        
}
Grumous answered 11/1, 2012 at 2:36 Comment(1)
You didn't answer the question. What he want is to check whether a ip connection is actually existing or not.Floyd

© 2022 - 2024 — McMap. All rights reserved.