首页 > 解决方案 > CNCopyCurrentNetworkInfo 与 iOS 13

问题描述

Apple 在 iOS 13 中更改了有关 WiFi 的一些内容。如果您想使用 CNCopyCurrentNetworkInfo,您的应用需要具备以下条件之一

资料来源: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 信息功能。

谢谢你的帮助!

标签: iosswiftcaptivenetworkios13nehotspothelper

解决方案


正如我在Apple Developer ForumsCNCopyCurrentNetworkInfo上所说,现在使用受到限制。

查看WWDC 19 会议 713,网络进步,第 2 部分(可能是演示文稿的 75%)。CNCopyCurrentNetworkInfo现在仅在以下三种情况下可供您的应用使用:

如果您不满足其中至少一项条件,iOS 13CNCopyCurrentNetworkInfo将始终返回nil

更新:从 iOS 13 Developer Beta 6 开始,Apple 终于更新了文档以记录更改


推荐阅读