2

I am using the below code to retrieve the SSID of the WiFi network the iPod is connected.

NSArray *ifs = (id)CNCopySupportedInterfaces();
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
    info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
    NSLog(@"%s: %@ => %@", __func__, ifnam, info);
    if (info && [info count]) {
        break;
    }
    [info release];
}

Sometimes this code is not returning the proper SSID of the network my device is connected.Any pointers on why the SSID is not retrieved correctly? Does CNCopyCurrentNetworkInfo package dependent on the iOS version of the device?

Thanks.

Cooldude
  • 31
  • 3
  • 9

2 Answers2

6
  1. add SystemConfiguration.framework to project.

  2. import < SystemConfiguration/CaptiveNetwork.h >

  3. CFArrayRef myArray = CNCopySupportedInterfaces();
    CFStringRef interfaceName = CFArrayGetValueAtIndex(myArray, 0);
    CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(interfaceName);
    NSDictionary *dict = ( NSDictionary*) captiveNtwrkDict;
    NSString* ssid = [dict objectForKey:@"SSID"];
    NSLog(@"%s ssid : %@",__FUNCTION__, [ssid description]);
    
  4. For iOS 12 and later, you must enable it from capabilities.

Important To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID. Documentation link

Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
vualoaithu
  • 936
  • 10
  • 9
0

Yes. CNCopyCurrentNetworkInfo is available only in iOS 4.1 and later.

For more info ,please look at the developer.apple SystemConfiguration Reference

you can check the sample code here

Community
  • 1
  • 1
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102