前言:更新了iOS12系统后,发现获取不到已连接wifi的ssid信息,12系统以前手机可以获取,搜集了一翻资料得到答案
1、在Capabilities中,激活Access WiFi Infomation项
2、去开发者账号appid打开Access WiFi Infomation权限
获取代码
//导入SystemConfiguration.framework框架
#import <SystemConfiguration/CaptiveNetwork.h>
+(NSString *)fetchSSIDInfo
{
NSString *currentSSID = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();
if (myArray != nil){
NSDictionary* myDict = (__bridge NSDictionary *) CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (myDict!=nil){
currentSSID=[myDict valueForKey:@"SSID"];
} else {
currentSSID=@"<<NONE>>";
}
} else {
currentSSID=@"<<NONE>>";
}
CFRelease(myArray);
return currentSSID;
}