CNCopyCurrentNetworkInfo is returning nil in iOS 13

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!

Replies

I am having this exact same issue as well. Also configuring the network using NEHotspotConfiguration, and CNCopyCurrentNetworkInfo still returning nil for SSID afterwards. Any help with this would be appreciated.

As an update, I just downloaded the iOS 13.1 version (build 17A844) that was released today and it seems to be working fine now. It could've just been a bug with iOS 13.0.

This is still not working for me in iOS 13.1. I am getting nil for,


let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String: AnyObject]

I'm experiencing the same issue even with the iOS 13.1.2 update.


Our app always connects to our network with NEHotspotConfigurationManager. Sometimes we can see the SSID and sometimes its nil. The network has no internet connection. Whether its nil or not seems very random. A device reboot seems to solve the issue.

I has the issue on iPhone X (but not on other devices) with iOS 13.1.2 where the SSID was available for a few minutes after a power cycle; iOS 13.1.3 released today seems to have fixed the issue.

iOS 13.1.3 works some days, but from yesterday it doesn`t works again, very unstable.

the same for me.


details:

a) demo app, works fine on iPhone 11 (ios 13)

b) does nto work on iPhone 6plus


fix: reboot iPhone6 !!


anyway:

1) you must add usual keys (for geloc !)

NSLocationAlwaysAndWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

NSLocationUsageDescription</key>

NSLocationWhenInUseUsageDescription


2) add usual dance in permission:



....

import CoreLocation


class ViewController: UIViewController, CLLocationManagerDelegate {


// for iOS13:

var locationManager = CLLocationManager()


override func viewDidLoad() {

super.viewDidLoad()


if #available(iOS 13.0, *) {

let status = CLLocationManager.authorizationStatus()

if status == .authorizedWhenInUse {

updateWiFi()

} else {

locationManager.delegate = self

locationManager.requestWhenInUseAuthorization()

}

} else {

updateWiFi()

}

}



func updateWiFi() {

let arr = currentSSIDs()

print(arr)

}




func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

if status == .authorizedWhenInUse {

updateWiFi()

}

}


}




func currentSSIDs() -> [String] {

guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {

return []

}

return interfaceNames.flatMap { name in

print(name)

guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String:AnyObject] else {

return nil

}

guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {

return nil

}

return ssid

}

}






I started form Eskimo sample.


(see also at:

// see: https://github.com/HackingGate/iOS13-WiFi-Info)

I have exactly the same problem in iOS 13.x. It happens randomly.

(I find a similar post written in last year for reference: https://forums.developer.apple.com/thread/103717)

I am also having the same problem on iOS 13.x, where it often returns nil even when location permissions are granted (and the fetch WiFi Info entitlement).


When running in the foreground, even with "Always" location permissions CNCopyCurrentNetworkInfo returns nil. On the iOS12 device I have, it always returns a valid object as you would expect.


Is there a step I am missing for this? It seems others are still having this issue too.