检测wifi是否启用(无论是否连接)
对于 GPS 跟踪应用程序来说,在打开 WIFI 的情况下记录位置信号会导致数据非常不精确或存在间隙。
在开始跟踪之前,我已使用可达性查询来检测 wifi 是否可用。问题是,如果进行该查询时,wifi 已启用但未连接到网络,则表明无法通过 wifi 访问互联网,但这并不表明该设置是否在设置应用程序中被禁用。这意味着,如果用户开始跑步并在跑步中建立连接,他们将从 wifi 而不是 GPS 或手机网络获得位置信号。因此,这些数据点的准确度可以> 10米所以我想跳过那个点。问题是,在 wifi 上,他们会有一个很大的空白期,其中没有记录他们的信号。
那么如何检查 wifi 是否已启用但已断开?
我已经阅读了我能找到的所有其他可达性讨论,但这似乎是一个差距,许多响应错误地表明可达性解决了这个问题。
...而且我不会需要 wifi - 只是提醒他们它已启用,因此在锻炼过程中的某个时刻他们的位置数据可能会丢失(由于不准确)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自从你问起以来已经有一段时间了,但我刚刚遇到这个。
如果你想遵守苹果的规则,似乎没有什么办法可以做到。 sysctl 和 ioctl 不起作用,因为没有标志可以显示 WiFi 是否已启用。例如,如果 WiFi 被禁用或 WiFi 已启用但未连接,“UP”和“RUNNING”的标志将相同。
苹果自己的 WiFi 框架使用 mach 直接与内核通信,我怀疑苹果是否会允许在 AppStore 中使用此类代码。
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.
这是可能的,但解决方案是模糊且丑陋的。简而言之,如果您看到两个名为“awdl0”的接口,则 WiFi 已启用,只有一个接口则已禁用。
请参阅检测 iOS 上启用/禁用 WiFi 的更好方法? 以获得更完整的描述和示例代码。
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.