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

2

7

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).

Chambless answered 5/1, 2012 at 15:5 Comment(1)
I was trying to achieve the same: https://mcmap.net/q/1474529/-ios-how-to-query-wifi-stateMaking
A
2

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.

Ashburn answered 27/4, 2012 at 18:31 Comment(0)
D
0

This IS possible, but the solution is obscure and ugly. The short answer is that if you see TWO interfaces with the name "awdl0" then WiFi is enabled, just one and it's disabled.

See Better way to detect WiFi enabled/disabled on iOS? for a more complete description and sample code.

Dicta answered 1/2, 2017 at 0:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.