位置权限对话框会在iOS 10中提示大量时间

在iOS 10中,有时在安装应用程序时,位置权限提示会打开大量时间并挂起所有应用程序,无法进一步移动。

这里是我的代码在iOS 10之前

-(void)startLocationManager{ self.locationManager=[[CLLocationManager alloc]init]; self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; self.locationManager.delegate=self; if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } [self.locationManager startUpdatingLocation]; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ if (self.myCurrentLocation==nil) { self.myCurrentLocation=[locations lastObject]; [[WALocationManager WALocationSharedInstance] checkLatestLocation]; } else{ if (self.myCurrentLocation.horizontalAccuracy < 0){ return; } self.myCurrentLocation=[locations lastObject]; if([[WALocationManager WALocationSharedInstance] currentLocation]!=self.myCurrentLocation ){ } } } 

在我的plist文件中,

 <key>NSLocationAlwaysUsageDescription</key> <string>This app will use your location to get most nearyby activity around you.</string> <key>NSLocationWhenInUseUsageDescription</key> <string>This app will use your location.</string> 

无论iOS 10如何,只有授予了权限,您才应该开始您的位置更新,您还应该在请求权限之前检查权限是否已被授予:

 -(void)startLocationManager{ self.locationManager=[[CLLocationManager alloc]init]; self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; self.locationManager.delegate=self; // Check for current permissions [self checkLocationAuth:[CLLocationManager authorizationStatus]]; } -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ [self checkLocationAuth:status]; } -(void)checkLocationAuth:(CLAuthorizationStatus)status{ switch (status) { case kCLAuthorizationStatusAuthorizedWhenInUse: case kCLAuthorizationStatusAuthorizedAlways: [self.locationManager startUpdatingLocation]; break; // did not ask for permission, ask now case kCLAuthorizationStatusNotDetermined: if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } else { // iOS < 8? implicitly request permission [self.locationManager startUpdatingLocation]; } break; // Also need to handle failures, etc default: break; } } 

可能是你可以尝试下面的检查,看看是否有帮助:

每次不要调用requestWhenInUseAuthorization

检查locationServicesEnabledauthorizationStatus ,只有当authorizationStatuskCLAuthorizationStatusDeniedlocationServicesEnabled返回false ,才调用requestWhenInUseAuthorization

喜欢,

 if(![CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } } 

希望它会帮助:)