背景
iOS14.0之前定位是不区分精确位置的,iOS14.0之后,如果不开启精确位置,就获取不到手机当前连接的wifi信息。
检查是否开启定位代码
+ (BOOL)isOpenLocation
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if(kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status || kCLAuthorizationStatusNotDetermined == status) {
return NO;
}
return YES;
}
检查精确位置代码
-(BOOL)isAccuracyLocation{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
if( @available(iOS 14.0, *)) {
if (locationManager.accuracyAuthorization == CLAccuracyAuthorizationReducedAccuracy) {
//没有开启精准定位
return NO;
}else{
//开启了精准定位
return** YES;
}
} else {
// Fallback on earlier versions
return YES;
}
}
精确位置枚举
- CLAccuracyAuthorizationFullAccuracy : 开启精确位置;
- CLAccuracyAuthorizationReducedAccuracy : 开启位置。
跳转到设置
+ (void)jumpAppSettingPage {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
if ( @available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
}];
} else {
[[UIApplication sharedApplication] openURL:url];
}
}
}
后记
iOS14.0之前默认开启了定位即开启了精确位置