在 iOS13 上请求 Always 权限期间,用户可以点击“允许一次”,这将调用具有状态的适当委托,kCLAuthorizationStatusAuthorizedWhenInUse
但再次请求“始终”以 调用委托kCLAuthorizationStatusAuthorizedAlways
。为什么?当其他组合像您总是要求的那样只工作一次时,您会得到它,即使再次调用也不会调用具有状态的委托。
要测试的示例代码:
@import CoreLocation;
@interface ViewController () <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
}
- (IBAction)doauthloc:(id)sender {
[self.locationManager requestAlwaysAuthorization];
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch(status) {
case kCLAuthorizationStatusNotDetermined:NSLog(@"AUTH STATUS:kCLAuthorizationStatusNotDetermined"); break;
case kCLAuthorizationStatusRestricted:NSLog(@"AUTH STATUS:kCLAuthorizationStatusRestricted"); break;
case kCLAuthorizationStatusDenied:NSLog(@"AUTH STATUS:kCLAuthorizationStatusDenied"); break;
case kCLAuthorizationStatusAuthorizedAlways:NSLog(@"AUTH STATUS:kCLAuthorizationStatusAuthorizedAlways"); break;
case kCLAuthorizationStatusAuthorizedWhenInUse:NSLog(@"AUTH STATUS:kCLAuthorizationStatusAuthorizedWhenInUse"); break;
};
}
@end