On iOS 4.1+, you can do this:
#import <SystemConfiguration/CaptiveNetwork.h>
- (id)fetchSSIDInfo
{
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];
}
[ifs release];
return [info autorelease];
}
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>;
}
ARC 版本
Here's the cleaned up ARC version
- (id)fetchSSIDInfo { NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces(); NSLog(@"Supported interfaces: %@", ifs); id info = nil; for (NSString *ifnam in ifs) { info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam); NSLog(@"%@ => %@", ifnam, info); if (info && [info count]) { break; } } return info; }