CNCopySupportedInterfaces() returns NULL

My iOS 14 app needs to find the name of the currently connected network. However, the following code snippet always returns NULL:

CFArrayRef interfacesArray = CNCopySupportedInterfaces();

The Xcode console has this output during runtime:

[] nehelper sent invalid result code [1] for Wi-Fi information request

I have the following entitlements/capabilities set:

  • Access WiFi Information
  • Wireless Accessory Configuration

What else is needed?

Replies

First up, the Wireless Accessory Configuration is irrelevant to this issue. You should remove that capability.

Second, the API you’re heading towards, CNCopyCurrentNetworkInfo, has been deprecated in favour of -[NEHotspotNetwork fetchCurrentWithCompletionHandler:]. That doesn’t change the access control story, but it’s a lot easier to use.

Finally, the access control story for these APIs is complex. It’s covered well in the CNCopyCurrentNetworkInfo documentation . The -fetchCurrentWithCompletionHandler: docs haven’t been updated for yet, but you can find the same info in the <NetworkExtension/NEHotspotNetwork.h> header.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Found this in the <NetworkExtension/NEHotspotNetwork.h> header:


@method fetchCurrentWithCompletionHandler:completionHandler:
@discussion This method returns SSID and BSSID of the current Wi-Fi network when the requesting application meets one of following 4 requirements: 
1. application is using CoreLocation API and has user's authorization to access precise location.
2. application has used NEHotspotConfiguration API to configure the current Wi-Fi network.
3. application has active VPN configurations installed.
4. application has active NEDNSSettingsManager configuration installed.
- - -

So be it... But you'd think there'd be a simpler way just to get the SSID string!