Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"];      }  }  
like image 936
Thyraz Avatar asked Jul 22 '15 06:07

Thyraz


People also ask

How do I find my SSID on my Iphone 6?

How to find SSID on iOS: Go to Settings > Wi-Fi. The network name (SSID) you are connected to will have a check mark next to it.


2 Answers

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.

like image 116
Pablo A. Avatar answered Oct 12 '22 17:10

Pablo A.


In the GM for iOS 9, it seems like this is enabled again. In fact, it's not even listed as deprecated in the online documentation, however the CaptiveNetwork header file does have the following:

CNCopySupportedInterfaces (void) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_8, __MAC_NA, __IPHONE_4_1, __IPHONE_9_0, CN_DEPRECATION_NOTICE); 

So, it is working in the iOS 9 GM, but not sure for how long :)

like image 42
lewiguez Avatar answered Oct 12 '22 16:10

lewiguez