ios - CNCopyCurrentNetworkInfo 与 iOS 13
问题描述
Apple 在 iOS 13 中更改了有关 WiFi 的一些内容。如果您想使用 CNCopyCurrentNetworkInfo,您的应用需要具备以下条件之一
- 有权访问位置的应用
- 您的应用是当前启用的 VPN 应用
- 您的应用通过 NEHotspotConfiguration 配置了设备当前使用的 WiFi 网络
资料来源:WWDC 19 第 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 13CNCopyCurrentNetworkInfo
总是返回 nil。
我的应用程序设置了访问 WiFi 信息功能。
谢谢你的帮助!
解决方案
正如我在Apple Developer ForumsCNCopyCurrentNetworkInfo
上所说,现在使用受到限制。
查看WWDC 19 会议 713,网络进步,第 2 部分(可能是演示文稿的 75%)。CNCopyCurrentNetworkInfo
现在仅在以下三种情况下可供您的应用使用:
- 有权访问位置的应用
- 您的应用是当前启用的 VPN 应用
- 您的应用通过NEHotspotConfiguration配置了设备当前使用的 WiFi 网络
如果您不满足其中至少一项条件,iOS 13CNCopyCurrentNetworkInfo
将始终返回nil
。
更新:从 iOS 13 Developer Beta 6 开始,Apple 终于更新了文档以记录更改。
推荐阅读
- ios - Swift 让 UITableView 填满手机的整个视口
- python - 如何将元组排序和分组为 CSV 以在 Python 中返回平均值和求和值
- javascript - 从其他按钮触发按钮单击
- svelte - 从开槽组件发出的事件
- javascript - Shopify - 在内联部分/片段脚本中使用您的 JS 库等
- tensorflow - `tf.data.Dataset` 在 CPU 上运行,除了 `PrefetchDataset`?
- c# - Chrome 未在指定的移动设备上运行(移动仿真模式)
- tensorflow - 使用 tensorflow 进行数据增强后生成的图像变体数量
- c# - Filewatcher 和队列管理
- programming-languages - 是否可以围绕实体-组件-系统架构建立一种语言?