【发布时间】:2019-10-28 05:37:03
【问题描述】:
Apple 在 iOS 13 中更改了有关 WiFi 的一些内容。如果您想使用 CNCopyCurrentNetworkInfo,您的应用需要具备以下条件之一
- 有权访问位置的应用
- 您的应用是当前启用的 VPN 应用
- 您的应用通过 NEHotspotConfiguration 配置了设备当前使用的 WiFi 网络
来源:WWDC 19 session 713
我正在使用 NEHotspotConfiguration 配置网络,但这样做后我无法再获取当前的 SSID。
以下代码在 iOS 12 上运行良好:
/// retrieve the current SSID from a connected Wifi network
private func retrieveCurrentSSID() -> String? {
let interfaces = CNCopySupportedInterfaces() as? [String]
let interface = interfaces?
.compactMap { [weak self] in self?.retrieveInterfaceInfo(from: $0) }
.first
return interface
}
/// Retrieve information about a specific network interface
private func retrieveInterfaceInfo(from interface: String) -> String? {
guard let interfaceInfo = CNCopyCurrentNetworkInfo(interface as CFString) as? [String: AnyObject],
let ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
else {
return nil
}
return ssid
}
使用 iOS 13 CNCopyCurrentNetworkInfo 总是返回 nil。
我的应用设置了访问 WiFi 信息功能。
感谢您的帮助!
【问题讨论】:
-
这里有同样的问题,似乎位置权限不足以获取 SSID 名称。你找到解决办法了吗?
-
对我来说同样的问题,但仍未解决。非常随机的事情是,如果我只是简单地关闭电话并打开电话,病房后一切正常;但是如果我以某种方式最终无法从
CNCopyCurrentNetworkInfo获取信息,无论我更改了多少次位置权限,我都不会从那里获取 ssid... -
我仍然面临同样的问题,有人解决了吗?
标签: ios swift captivenetwork ios13 nehotspothelper