Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use CaptiveNetwork to get the current WiFi Hotspot Name

I need to get the name of the currently connected Wi-Fi hotspot, e.g. "BT OpenZone"

I have been told it can be done with CaptiveNetwork specifically CNCopyCurrentNetworkInfo

My code so far:

#import <SystemConfiguration/CaptiveNetwork.h> ...  // Get the dictionary containing the captive network infomation CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(kCNNetworkInfoKeySSID);  // Get the count of the key value pairs to test if it has worked int count = CFDictionaryGetCount(captiveNtwrkDict); NSLog(@"Count of dict:%d",count); 

When the code runs on a device in a WiFi hotspot the captiveNtwrkDict is nil.

Has anyone managed to get it working? I cant find much documentation or any example code examples on CaptiveNetworks... any help would be much appreciated.

like image 525
Robert Avatar asked Jan 17 '11 11:01

Robert


1 Answers

You need to find out which networks are available, and then pass them into CNCopyCurrentNetworkInfo. For example:

CFArrayRef myArray = CNCopySupportedInterfaces(); CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); 

...and you can then use the kCNNetworkInfoKeySSID on the dictionary you've got back (myDict) to find out the SSID. Don't forget to release/manage memory appropriately.

like image 181
lxt Avatar answered Sep 20 '22 22:09

lxt