iOS 12 适配WiFi
增加隐私权限
https://www.cnblogs.com/baitongtong/p/10179519.html
ios13又新增定位权限
别的不说,理解请看上篇文章
直接上代码// 当定位授权状态改变时
_- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status)
{
case kCLAuthorizationStatusDenied: // 拒绝授权
NSLog(@"授权失败:用户拒绝授权或未开启定位服务");
break;
case kCLAuthorizationStatusAuthorizedWhenInUse: // 在使用期间使用定位
NSLog(@"授权成功:用户允许应用“使用期间”使用定位服务");
if (geteventID >= 0) {
NSDictionary *ret = @{@"returnVal":[self currentWifiSSID]};
[self sendResultEventWithCallbackId:geteventID dataDict:ret errDict:nil doDelete:YES];
}
break;
}
}
//获取wifi名称
( NSString*)currentWifiSSID
{
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
NSDictionary *SSIDInfo;
for (NSString *interfaceName in interfaceNames) {
SSIDInfo = CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
BOOL isNotEmpty = (SSIDInfo.count > 0);
if (isNotEmpty) {
break;
}
}
NSString * ssid = @"";
if (![[SSIDInfo objectForKey:@"SSID"] isEqual:@""]&&[SSIDInfo objectForKey:@"SSID"]!=nil) {
ssid = [SSIDInfo objectForKey:@"SSID"]; //包含信息SSIDInfo_
}
return ssid;
}
{
[setHostComputer launch];
if (_locationManager == nil) {
_locationManager = [CLLocationManager new];
}
geteventID = [paramsDict_ integerValueForKey:@"cbId" defaultValue:-1];
if (_locationManager != nil) {
// 请求“使用期间”使用定位服务
if (@available(iOS 13, *)) {
if (CLLocationManager.authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {//开启了权限,直接搜索
if (geteventID >= 0) {
NSDictionary *ret = @{@"returnVal":[self currentWifiSSID]};
[self sendResultEventWithCallbackId:geteventID dataDict:ret errDict:nil doDelete:YES];
}
} else if (CLLocationManager.authorizationStatus == kCLAuthorizationStatusDenied) {//如果用户没给权限,则提示
\[UIAlertController alertControllerWithTitle:@"定位权限关闭提示" message:@"你关闭了定位权限,导致无法使用WIFI功能" preferredStyle:UIAlertControllerStyleAlert\];
} else {//请求权限
\_locationManager.delegate = self;
\[\_locationManager requestWhenInUseAuthorization\];
}
} else {
if (geteventID >= 0) {
NSDictionary \*ret = @{@"returnVal":\[self currentWifiSSID\]};
\[self sendResultEventWithCallbackId:geteventID dataDict:ret errDict:nil doDelete:YES\];
}
}
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章