Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell with Objective-C if the iPhone is connected to a wifi network?

In the context of an Objective-C, iPhone application, I need to be able to tell whether the iPhone is connected to a wifi network, and if possible listen to changes in this state.

Does anyone know how to do this?

thanks, gabouy

like image 649
gabouy Avatar asked Aug 14 '09 18:08

gabouy


2 Answers

As others mentioned, the Reachablity sample is a good place to start, however, their answers don't spell it out enough for my tastes. Within the Reachablity sample the code is spread out and doesn't show you how to handle the simplest case. For the simplest case (not listening to changes in state) I can save you the effort of having to collate the right lines yourself.

Copy the Reachability class from the Reachablity sample into your project, include it in your class, and use the following code:

if ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] != ReachableViaWiFi) {
    //Code to execute if WiFi is not enabled
}
like image 104
Gordon McCreight Avatar answered Oct 10 '22 02:10

Gordon McCreight


Check out the Reachability sample.

like image 24
Dave Avatar answered Oct 10 '22 03:10

Dave