Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SystemConfiguration.CaptiveNetwork doesn't work on iOS 12

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.

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
}
like image 891
Victor Lobe Avatar asked Jun 08 '18 20:06

Victor Lobe


1 Answers

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

enter image description here

like image 187
Ckwanted Avatar answered Sep 20 '22 17:09

Ckwanted