iOS 12 適配WiFi
增加隱私權限
https://www.cnblogs.com/baitongtong/p/10179519.html
ios13又新增定位權限
別的不說,理解請看上篇文章
iOS - 適配 iOS 13 之工兵連掃雷
直接上代碼// 當定位授權狀態改變時
- (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; } - (void)get:(NSDictionary *)paramsDict_ { [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]; } } } }