How to get Wifi SSID in iOS9 after CaptiveNetwork is deprecated and calls for Wifi name are already blocked

Thyraz picture Thyraz · Jul 22, 2015 · Viewed 42.8k times · Source

Until today I used the CaptiveNetwork Interface to display the name of the currently connected Wifi. The iOS 9 Prerelease reference already stated, that the CaptiveNetwork methods are depracted now, but they still worked at the beginning.

With the newest version Apple seems to have blocked this calls already (maybe due to privacy concerns?).

Is there any other way to get the name of the current Wifi?

This is how I obtained the SSID until today, but you only get nil now:

#import <SystemConfiguration/CaptiveNetwork.h>

NSString *wifiName = nil;  
NSArray *interFaceNames = (__bridge_transfer id)CNCopySupportedInterfaces(); 

for (NSString *name in interFaceNames) { 
    NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)name); 

    if (info[@"SSID"]) { 
        wifiName = info[@"SSID"]; 
    } 
} 

Answer

Pablo A. picture Pablo A. · Jul 23, 2015

Register your app as Hotspot helper.

#import <NetworkExtension/NetworkExtension.h>  

NSArray * networkInterfaces = [NEHotspotHelper supportedNetworkInterfaces];  
NSLog(@"Networks %@",networkInterfaces);  

UPDATE (Sept. 11th, 2015)

The following Captive Network APIs have been re-enabled in the latest version of iOS 9 instead.

  • CNCopySupportedInterfaces
  • CNCopyCurrentNetworkInfo

UPDATE (Sept. 16th, 2015)

If you still prefer to use NetworkExtension and Apple gave you permission to add the entitlements, then you can do this to get the wifi information:

for(NEHotspotNetwork *hotspotNetwork in [NEHotspotHelper supportedNetworkInterfaces]) {
    NSString *ssid = hotspotNetwork.SSID;
    NSString *bssid = hotspotNetwork.BSSID;
    BOOL secure = hotspotNetwork.secure;
    BOOL autoJoined = hotspotNetwork.autoJoined;
    double signalStrength = hotspotNetwork.signalStrength;
}

NetworkExtension provides you some extra information as secure, auto joined or the signal strength. And it also allows you to set credential to wifis on background mode, when the user scans wifis around.