26

Apple changed some things regarding WiFi with iOS 13. 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

Source: WWDC 19 session 713

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:

/// retrieve the current SSID from a connected Wifi network  
private func retrieveCurrentSSID() -> String? {  
    let interfaces = CNCopySupportedInterfaces() as? [String]  
    let interface = interfaces?  
        .compactMap { [weak self] in self?.retrieveInterfaceInfo(from: $0) }  
        .first  

    return interface  
}  

/// Retrieve information about a specific network interface  
private func retrieveInterfaceInfo(from interface: String) -> String? {  
    guard let interfaceInfo = CNCopyCurrentNetworkInfo(interface as CFString) as? [String: AnyObject],  
        let ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String  
        else {  
            return nil  
    }  
    return ssid  
} 

With iOS 13 CNCopyCurrentNetworkInfo always returns nil.

My app has the Access WiFi Information Capability set.

Thanks for your help!

MikeB
  • 1,619
  • 2
  • 15
  • 27
  • 1
    Same issue here and it seems that location permission it is not enough to get SSID name. Did you find a solution? – MatterGoal Aug 09 '19 at 15:27
  • 1
    Same issue for me and still not solved. The very random thing, is that if I simply turn off and on the phone, everything works fine after wards; but if I somehow end up in the case I can't get the informations from `CNCopyCurrentNetworkInfo`, not matter how many times I change the location permissions, I'm not gonna get the ssid from there... – Alessandro Francucci Oct 10 '19 at 14:45
  • 1
    I am still facing the same issue,anyone got fix for this? – guru Nov 26 '19 at 10:44

9 Answers9

14

As I said on the Apple Developer Forums use of CNCopyCurrentNetworkInfo is now limited.

Check out WWDC 19 session 713, Advances in Networking, Part 2 (maybe 75% of the way through the presentation). CNCopyCurrentNetworkInfo is now only available to your app in three cases:

  • 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

If you don't meet at least one of these conditions CNCopyCurrentNetworkInfo will always return nil in iOS 13.

UPDATE: As of iOS 13 Developer Beta 6, Apple has finally updated the documentation to note the changes.

Robbie Trencheny
  • 549
  • 1
  • 4
  • 19
  • 4
    Thanks for your response. But thats exactly what I cited above. I do meet one of the requirements. I use NEHotspotConfiguration to connect to a network. After I get a success I start checking the current SSID using the code I posted above. I do this because I need to know that the joining process was successful since we do not get a callback from NEHotspotConfiguration that tells us that. When checking I retry calling retrieveCurrentSSID a few times and timeout if I don't find the expected network to be connected – MikeB Jun 19 '19 at 06:54
  • ....I don't know how I entirely missed that you quoted my post. Sorry about that! My guess would be there is a bug with using `CNCopyCurrentNetworkInfo` via `NEHotspotConfiguration` at the moment then. Maybe try (as a temporary fix/to ensure the rest of your code is good) enable Core Location to see if you are then able to access? – Robbie Trencheny Jun 19 '19 at 07:33
  • Thats a good idea. I'll try that just to make sure my code is not wrong. Would hate to have to ask for location permissions in my production code though :D – MikeB Jun 19 '19 at 07:46
  • 3
    I was having the same problem. I meet `Apps with permission to access location` (if that means Core Location always authorization), but still getting `nil` from the calls. I just realized I was missing the `Access Wi Fi information capability` as described in here https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo. – Markus Rautopuro Jul 03 '19 at 12:54
  • @RobbieTrencheny Is there any way to get Wi-Fi Network Info without Location Permission? I have enabled Access WiFi Information and the Hotspot Configuration in capabilities but not able to find network info. – Mitesh Mistri Jul 26 '19 at 08:03
  • @MitsMistri I quoted Apple's own keynote session, so unless they change their minds before iOS 13 is released to the public, no. – Robbie Trencheny Aug 06 '19 at 06:16
  • Apple just updated the documentation to discuss iOS 13 changes [here](https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo). – Robbie Trencheny Aug 07 '19 at 17:47
  • 6
    I'm still getting nil from `CNCopyCurrentNetworkInfo` despite having _location permissions_ set to _always_ and Wi-Fi information capability on... Until iOS 13 it worked perferctly – Ariel Steiner Oct 09 '19 at 13:54
  • @ArielSteiner I'm still getting this issue as well – DivideByZer0 Jan 08 '20 at 20:51
  • If I give Allow once permission then it does not fetch WiFi SSID – shaqir saiyed Jan 20 '20 at 07:11
  • For anyone going to watch the video, its mentioned at 53:45 – Ric Santos Jun 24 '20 at 00:41
4

I have a similar issue in my app. I have submitted a feedback form to Apple and got a response stating:

Potential fix identified - For a future OS update

So hopefully, this will be resolved before the final release (not in iOS 13 Beta 4 though).

For a workaround, you can set joinOnce = false in your NEHotspotConfiguration. In my app, it allowed me to access CNCopySupportedInterfaces, but required me to remove configuration every time my app was closed.

Hope it helps!

Edit:

It seems that in iOS 13 beta 5 issue no longer persists. In my application, I can access CNCopyCurrentNetworkInfo again (thus confirming the Wi-Fi has been connected), no matter if NEHotspotConfiguration.joinOnce flag is set to true or false.

4

If someone tries to use CNCopyCurrentNetworkInfo via the case Apps with permission to access location (via the CoreLocation API and CLLocationManager) don't forget to enable the Access WiFi Information capability (See also this answer here). This should be mandatory since iOS 12, but I needed to update an App which was last tested before iOS 12. See also from the Discussion Section here:

Important

To use this function, an app linked against iOS 12 or later must enable the Access WiFi Information capability in Xcode. For more information, see Access WiFi Information Entitlement. Calling this function without the entitlement always returns NULL when linked against iOS 12 or later.

ronatory
  • 7,156
  • 4
  • 29
  • 49
2

Must verify that

<key>com.apple.developer.networking.wifi-info</key>
<true/>

is added to Entitlements-Release.plist, mostly its just added to Entitlements-Debug.plist only

Tabish Sohail
  • 1,040
  • 2
  • 9
  • 22
1

I believe that you match one of the following condition which is suggested by Apple:

1 :Apps with permission to access location

2 :Your app is the currently enabled VPN app

3 :Your app configured the WiFi network the device is currently using via NEHotspotConfiguration

In my case even i have location services enable when was facing the issue.

After some workaround here are i found the two solution which you can try:

1: Reboot the device. This works for me!!.

2: Update the OS if available.

I am not sure it helps you but in few cases it should work, few people suggest reboot 2-3 times work for them.

Another good news from Apple that they fix for this issue on iOS 13.3 beta version

guru
  • 2,727
  • 3
  • 27
  • 39
  • I got the same issue after installing iOS 14.0.1 security update, CNCopySupportedInterfaces always returned nil. After rebooting the device as suggested by gury, the problem disappeared and CNCopySupportedInterfaces was working again. – Daniel Mavrakis Oct 10 '20 at 09:14
0

For me, TryCopyCurrentNetworkInfo always return nil even with a network configured with NEHotspotConfiguration. I tried the the recommendation of Mateusz with setting the option JoinOne to false or true but it did not solve the issue.

Phone OS is 13.1.3 Access WiFi information is enabled in my profile It was working in iOS 12

AlexP
  • 419
  • 6
  • 13
0

I've spent hours trying to figure out a way to let CNCopyCurrentNetworkInfo works on iOS 13 with no results, no matter location permissions status or the fact that my app configured the current Wi-Fi network the device is currently using via NEHotspotConfiguration. It just does not work.

I finally came out with the reliable solution to get the SSID through getConfiguredSSIDsWithCompletionHandler: method of NEHotspotConfigurationManager.

Here's a simple example:

static func retrieveCurrentSSID(  callback: @escaping ( String? ) -> Void ){
    NEHotspotConfigurationManager.shared.getConfiguredSSIDs { ( networkSSIDs ) in
        callback( networkSSIDs.first )
    }
}

Garba
  • 126
  • 2
  • 8
0

Seems silly, but in some cases one must reboot to get this to work properly even though this worked fine before the in case the iOS 13 beta update.

see also at: https://forums.developer.apple.com/thread/123244

Yohst
  • 1,671
  • 18
  • 37
ingconti
  • 10,876
  • 3
  • 61
  • 48
0

I had same issue from iOS 13.0 but it seems that apple fixed in 13.3 The requirement in the doc that it should be either a network added by the app or that location should be enabled or that app had an active VPN did not work for 13.1 13.1 13.2

AlexP
  • 419
  • 6
  • 13