简体   繁体   English

SystemConfiguration.CaptiveNetwork在iOS 12上不起作用

[英]SystemConfiguration.CaptiveNetwork doesn't work on iOS 12

I have a function that detects the current SSID from the user. 我有一个功能,可以检测用户的当前SSID。 Unfortunately this doesn't work anymore with iOS 12. This means it just jumps over the if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { 不幸的是,这不再适用于iOS 12.这意味着它只是跳过if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { part. if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {部分。 Maybe it's just a bug or it's deprecated. 也许这只是一个错误或它被弃用了。 I've found nothing on Apple Docs. 我在Apple Docs上找不到任何内容。 On older iOS 11, 10, and 9 devices, it works well. 在较旧的iOS 11,10和9设备上,它运行良好。

Here's my Code: 这是我的代码:

func getWiFiSsid() -> String? {
    if let interfaces = CNCopySupportedInterfaces() as NSArray? {
        for interface in interfaces {
            if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {

                ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String


            }
        }
    }
    return ssid
}

To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. 要在iOS 12及更高版本中使用此功能,请在Xcode中为您的应用启用Access WiFi信息功能。 When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID. 启用此功能后,Xcode会自动将Access WiFi信息权利添加到您的权利文件和应用程序ID中。

https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo?language=objc https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo?language=objc

在此输入图像描述

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM