How to check local Wi-Fi connection
I am writing an application that connects to a static IP address on a local network. How can I check if I have a local network connection? I want to connect to http://192.168.2.5 and I tried to use the class Rechability
, but it returns FALSE
while the device is definitely connected (when I don't check, the app works fine, so there is a connection):
Reachability *r = [Reachability reachabilityWithHostName:@"http://192.168.2.5"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
How should this work out?
Thomas
a source to share
I was under the impression that you were not following the usage guidelines as described in the ReadMe and sample code. You seem to be checking the status synchronously and immediately, which doesn't work. Take a look at the applicationDidFinishLaunching method in ReachabilityAppDelegate.m which shows how to wait for a response to enter (via reachabilityChanged) before you check the status. Also, you might need to call startNotifer to get this to work.
a source to share