How to get Wifi SSID in iOS9 after CaptiveNetwork is deprecated

ghz 7months ago ⋅ 82 views

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"]; 
    } 
} 

Answers

Unfortunately, as of iOS 12 and later, Apple has restricted access to Wi-Fi network information due to privacy and security concerns. The CaptiveNetwork API you were using is now deprecated and no longer reliable for obtaining the name of the currently connected Wi-Fi network.

However, there is an alternative approach you can consider:

NEHotspotNetwork

You can use the NetworkExtension framework's NEHotspotNetwork class to obtain information about the current Wi-Fi network. This class provides access to information about nearby Wi-Fi networks, including the SSID.

Here's how you can use it:

#import <NetworkExtension/NEHotspotNetwork.h>

NSArray<NEHotspotNetwork *> *hotspotNetworks = [NEHotspotHelper supportedNetworkInterfaces];

for (NEHotspotNetwork *network in hotspotNetworks) {
    NSString *ssid = network.SSID;
    // Do something with the SSID
}

Caveats:

  • This approach requires the App Groups capability to be enabled in your app's capabilities settings.
  • You'll need to add the "com.apple.developer.networking.HotspotHelper" entitlement to your app's entitlements file.
  • This approach may not work in all scenarios and is subject to Apple's restrictions and changes in future iOS versions.

Before implementing this approach, carefully review Apple's documentation and guidelines related to privacy and usage of network-related APIs to ensure compliance with App Store guidelines.