Thomas Joos
Thomas Joos

Reputation: 2451

How to check a local wifi connection

I'm writing an app which connects to a static ip address in 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 using the Rechability class but it returns FALSE, while the device is definitely connected ( when i don't do the 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 work this out?

Thomas

Upvotes: 2

Views: 1130

Answers (2)

Dunkelstern
Dunkelstern

Reputation: 1624

Problem i see with this: "http://" is not a hostname ;)

You should check for your ip only without the http part!

(i know this is old, but there was no real answer and you might find this via searching)

Upvotes: 0

Thomas Tempelmann
Thomas Tempelmann

Reputation: 12069

I have the impression you have not followed the usage rules as explained in the ReadMe and the sample code. You seem to check for the status synchronously and immediately, which is not working. Look at the applicationDidFinishLaunching method in ReachabilityAppDelegate.m which shows how to wait for the answer to come in (via reachabilityChanged) before you check the status. Also, you may need to call startNotifer to get this working.

Upvotes: 1

Related Questions