Apple更改了有关iOS 13 WiFi的一些内容。如果要使用CNCopyCurrentNetworkInfo,您的应用程序需要具有以下任一功能
资料来源: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信息功能集。
谢谢你的帮助!
最佳答案
正如我在Apple Developer Forums上说的那样,现在对CNCopyCurrentNetworkInfo
的使用受到限制。
查阅WWDC 19 session 713,网络高级知识,第2部分(可能是演示过程的75%)。 CNCopyCurrentNetworkInfo
现在仅在以下三种情况下可用于您的应用程序:
如果您不满足以下条件之一,则
CNCopyCurrentNetworkInfo
在iOS 13中将始终返回nil
。更新:从iOS 13 Developer Beta 6开始,Apple has finally updated the documentation to note the changes。
关于ios - CNCopyCurrentNetworkInfo与iOS 13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60377016/