SystemConfiguration.CaptiveNetwork在iOS 12上不起作用 [英] SystemConfiguration.CaptiveNetwork doesn't work on iOS 12

查看:299
本文介绍了SystemConfiguration.CaptiveNetwork在iOS 12上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能可以检测用户的当前SSID.不幸的是,这不适用于iOS12.这意味着它只是跳过了if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {部分.也许这只是一个错误或已被弃用.我在Apple Docs上什么都没找到. 在较旧的iOS 11、10和9设备上,它运行良好.

I have a function that detects the current SSID from the user. 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? { part. Maybe it's just a bug or it's deprecated. I've found nothing on Apple Docs. On older iOS 11, 10, and 9 devices, it works well.

这是我的代码:

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
}

推荐答案

要在iOS 12及更高版本中使用此功能,请在Xcode中为您的应用启用访问WiFi信息"功能.启用此功能后,Xcode会自动将Access WiFi信息权利添加到您的权利文件和应用ID中.

To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID.

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

这篇关于SystemConfiguration.CaptiveNetwork在iOS 12上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆