首先添加框架:SystemConfiguration.framework
然后引用#import<SystemConfiguration/CaptiveNetwork.h>
剩下的就是代码:
- (NSString *)currentWifiSSID {
NSString *ssid = nil;
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *ifnam in ifs) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info[@"SSID"]) {
ssid = info[@"SSID"];
}}
return ssid;}
值得一提的事,获取ssid必须在真机上,模拟器上不行。