I saw in the documentation https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo that, If you want to use CNCopyCurrentNetworkInfo your app needs to have one of the following
- Apps with permission to access location
- Your app is the currently enabled VPN app
- Your app configured the WiFi network the device is currently using via NEHotspotConfiguration
I am configuring a network using NEHotspotConfiguration but I can not get the current SSID anymore after doing so.
The following code worked fine with iOS 12:
func currentSsid() -> String? {
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
return nil
}
return interfaceNames.compactMap { name in
guard
let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String: AnyObject],
let ssid = info[kCNNetworkInfoKeySSID as String] as? String
else {
return nil
}
return ssid
}.first
}
With iOS 13
CNCopyCurrentNetworkInfo
always returns nil.My app has the Access WiFi Information Capability set.
Thanks for your help!