As of iOS 7 or 8, you can do this, which takes advantage of ARC and modules, which will automatically link in the needed framework:
@import SystemConfiguration.CaptiveNetwork;
/** Returns first non-empty SSID network info dictionary.
* @see CNCopyCurrentNetworkInfo */
- (NSDictionary *)fetchSSIDInfo
{
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, interfaceNames);
NSDictionary *SSIDInfo;
for (NSString *interfaceName in interfaceNames) {
SSIDInfo = CFBridgingRelease(
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
NSLog(@"%s: %@ => %@", __func__, interfaceName, SSIDInfo);
BOOL isNotEmpty = (SSIDInfo.count > 0);
if (isNotEmpty) {
break;
}
}
return SSIDInfo;
}
(This is a modernization of a code sample written for iOS 4.1+. The only changes were introducing clearer variable names and adopting ARC and modules.)
Example output:
2011-03-04 15:32:00.669 ShowSSID[4857:307] -[ShowSSIDAppDelegate fetchSSIDInfo]: Supported interfaces: (
en0
)
2011-03-04 15:32:00.693 ShowSSID[4857:307] -[ShowSSIDAppDelegate fetchSSIDInfo]: en0 => {
BSSID = "ca:fe:ca:fe:ca:fe";
SSID = XXXX;
SSIDDATA = <01234567 01234567 01234567>;
}
Note that no ifs are supported on the simulator. Test on your device.
Prior to 4.1, you might have some luck spelunking through the System Configuration dictionary. For example, using scutil
on my Mac:
$ scutil
> show State:/Network/Interface/en1/AirPort
<dictionary> {
Power Status : 1
SecureIBSSEnabled : FALSE
BSSID : <data> 0xcafecafecafe
SSID_STR : XXXX
SSID : <data> 0x012345670123456701234567
Busy : FALSE
CHANNEL : <dictionary> {
CHANNEL : 1
CHANNEL_FLAGS : 10
}
}
> exit