简体   繁体   English

检测wifi已启用(无论是否已连接)

[英]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. 对于GPS跟踪应用程序,在打开WIFI的情况下记录位置信号会导致真正不精确的数据或带有间隙的数据。

I've used the Reachability queries to detect if wifi is available prior to starting tracking. 我已经使用Reachability查询来检测在开始跟踪之前wifi是否可用。 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. 问题是,如果在进行该查询时启用了wifi但未连接到网络,则表明无法通过wifi访问互联网,但这并不表示设置应用中是否禁用了该设置。 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. 这意味着如果用户开始运行并且在中途运行连接,他们将从wifi而不是GPS或蜂窝网络获得位置信号。 Consequently the accuracy on those data points can be > 10 meters so I want to skip that point. 因此,这些数据点的准确度可能> 10米,所以我想跳过这一点。 The issue is that on wifi they'll have a large blank period where their signal wasn't recorded. 问题是,在wifi上,他们将有一个很大的空白时段,他们的信号没有被记录下来。

So how can I check if wifi is enabled but disconnected? 那么如何检查wifi是否已启用但已断开连接?

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). ...而且我不会要求 wifi - 只是提醒他们启用它的事实,因此在他们的锻炼中的某些时候他们的位置数据可能会丢失(由于不准确)。

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. 如果你想遵守Apple的规则,看起来没有办法做到这一点。 sysctl and ioctl won't work because there are no flags which will show you wether WiFi is enabled. sysctl和ioctl将无法工作,因为没有标志会显示WiFi已启用。 For example the flags for "UP" and "RUNNING" will be the same if WiFi is disabled or WiFi is enabled but not connected. 例如,如果禁用WiFi或启用WiFi但未连接,则“UP”和“RUNNING”的标志将相同。

Apple's own WiFi framework uses mach to directly communicate with the kernel and I doubt Apple would allows such code in the AppStore. Apple自己的WiFi框架使用mach直接与内核通信,我怀疑Apple会在AppStore中允许这样的代码。

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. 简短的回答是,如果您看到两个名称为“awdl0”的接口,则启用WiFi,只启用一个并禁用它。

See Better way to detect WiFi enabled/disabled on iOS? 请参阅更好的方法来检测iOS上启用/禁用WiFi? for a more complete description and sample code. 有关更完整的说明和示例代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查本地WiFi网络中的设备是否已使用其IP地址连接? - How to check whether a device in local WiFi network is connected or not using it's IP address? 在 iOS 上检测 WiFi 启用/禁用的更好方法? - Better way to detect WiFi enabled/disabled on iOS? 无论是否启用权利,Mac应用程序崩溃(由于权利而终止) - Mac application crashes (killed due to entitlements) regardless of whether entitlements are enabled 以编程方式检测 iOS 密码是否启用 - Programmatically detect whether iOS passcode is enabled or not 检测 Apple Pencil 是否连接到 iPad Pro - Detect whether Apple Pencil is connected to an iPad Pro 电话的当前IP地址,无论是通过WiFi还是3G连接 - Current IP address of phone, whether connected via WiFi or 3G 获取已连接的 wifi 路由器的制造商名称 - Get connected wifi Router's manufacturer name 连接到wifi但没有intenernet时如何检测互联网连接:iOS - How to detect internet connection when connected to wifi but no intenernet: iOS 如何检测iOS上是否正在进行个人wifi热点或录音? - How to detect whether personal wifi hotspot or recording is undergoing on iOS? 检测是否在Javascript中启用了运动和方向访问-iOS - Detect whether Motion & Orientation Access is enabled in Javascript - iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM