1.iOS 13 获取wifi名称需要先获取一下位置信息,可能是苹果对用户隐私的保护
NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
CGFloat version = [phoneVersion floatValue];
// 如果是iOS13 未开启地理位置权限 需要提示一下
if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined && version >= 13) {
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];
}
2.工程文件导入
#import <SystemConfiguration/CaptiveNetwork.h>
3.实现如下方法,可返回wifi名称
- (NSString *)currentWifiSSID
{
NSString*ssid =nil;
NSArray *ifs = (__bridge id)CNCopySupportedInterfaces();
for(NSString*ifnameinifs) {
NSDictionary*info = (__bridgeid)CNCopyCurrentNetworkInfo((__bridgeCFStringRef)ifname);
if(info[@"SSID"])
{
ssid = info[@"SSID"];
}else{
if(info[@"SSIDD"])
{
ssid = info[@"SSID"];
}
}
}
returnssid;
}
网友评论