Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect wifi enabled (regardless of whether it's connected)

For a GPS tracking app, recording location signals with WIFI turned on results in really imprecise data or data with gaps.

I've used the Reachability queries to detect if wifi is available prior to starting tracking. The problem is that if when that query is made the wifi is enabled but not connected to a network, it shows that the internet is not reachable via wifi, but that's not an indication of if the setting is disabled in the settings app. This means that if the user starts running and a connection is made mid-run, they'll get a location signal from the wifi instead of the GPS or cell network. Consequently the accuracy on those data points can be > 10 meters so I want to skip that point. The issue is that on wifi they'll have a large blank period where their signal wasn't recorded.

So how can I check if wifi is enabled but disconnected?

I've read all the other reachability discussions I could find but this seems to be the one gap with lots of responses incorrectly suggesting that reachability solves this out of the box.

...and I'm not going to require wifi - just alert them to the fact that it is enabled so at some point in their workout their location data might be lost (due to inaccuracy).

like image 498
earnshavian Avatar asked Jan 05 '12 15:01

earnshavian


1 Answers

It's been quite a while since you asked, but I just came across this one.

It doesn't look like there is any way to do it if you want to obey Apple's rules. sysctl and ioctl won't work because there are no flags which will show you wether WiFi is enabled. For example the flags for "UP" and "RUNNING" will be the same if WiFi is disabled or WiFi is enabled but not connected.

Apple's own WiFi framework uses mach to directly communicate with the kernel and I doubt Apple would allows such code in the AppStore.

like image 188
YllierDev Avatar answered Sep 28 '22 10:09

YllierDev