iOS Replacement for the Deprecated CNCopyCurrentNetworkInfo (Availability - iOS 4.1–14.0)

1.7k views Asked by At

hello i am using cncopycurrentnetworkinfo for getting the data (ssid,bssid) for the connected wifi network but according to the link https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo showing Deprecated and showing possible solution is using the method fetchCurrentWithCompletionHandler:(https://developer.apple.com/documentation/networkextension/nehotspotnetwork/3666511-fetchcurrentwithcompletionhandle) this is method of HotspotHelper and i also email [email protected] ask for that entitlement (com.apple.developer.networking.HotspotHelper) used by HotspotHelper but got rejected.

so is there any other possible solution?

2

There are 2 answers

0
pradip rathod On BEST ANSWER

https://developer.apple.com/forums/thread/675211?answerId=664741022#664741022

I got the answer from apple developer forum

+fetchCurrentWithCompletionHandler: does not require the Hotspot Helper entitlement. Unfortunately that fact is not documented officially (r. 74976266). Fortunately, there’s lots of good info about this method in the doc comments in <NetworkExtension/NEHotspotNetwork.h>.

here is the implemented example. hope this helps others

if (@available(iOS 14.0, *)) {
    [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) {
       NSString  *strSSID = [currentNetwork SSID];
    }];
} else {

    NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
    
    NSDictionary *info;
    
    for (NSString *ifnam in ifs) {
        
        info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        
        if (info && [info count]) {
            
            NSString  *strSSID = [info objectForKey:@"SSID"];
            break;
        }
    }
}
1
gnasher729 On

It seems that Apple doesn’t want any arbitrary app to have this information, most likely for privacy reasons. And I assume your app is not a hotspot helper. So there is no way to get that data on a newer iOS version.

You could add why you are needing this information. If it is to gather information about the user, then you have your answer. If not, then you may achieve your actual goal in a different way.