[英]iOS 13 call requestAlwaysAuthorization again after user “Allow Once” only
During requesting for Always permission on iOS13, the user can tap "Allow Once" which will call appropriate delegate with status kCLAuthorizationStatusAuthorizedWhenInUse
but requesting for "Always" again calls delegate with kCLAuthorizationStatusAuthorizedAlways
.在 iOS13 上请求 Always 权限期间,用户可以点击“允许一次”,这将调用状态为
kCLAuthorizationStatusAuthorizedWhenInUse
的适当委托,但再次请求“始终”以kCLAuthorizationStatusAuthorizedAlways
调用委托。 Why?为什么? When other combinations work only once like you request always, you get it and even calling again will not call delegate with status.
当其他组合像您总是要求的那样只工作一次时,您会得到它,即使再次调用也不会调用具有状态的委托。
Sample code to test:要测试的示例代码:
@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
It's a little confusing, isn't it?这有点令人困惑,不是吗? When you ask for Always and the user taps Allow Once, you are told that you got WhenInUse.
当您要求 Always 并且用户点击 Allow Once 时,您会被告知您获得了 WhenInUse。 But that doesn't actually matter.
但这实际上并不重要。 You have provisional Always.
你有临时的总是。 So:
所以:
When you subsequently go into the background and start monitoring visits or regions or whatever your location monitoring usage is, this will be converted into Always authorization for purposes of usage.当您随后 go 进入后台并开始监控访问或区域或您的位置监控使用情况时,这将转换为始终授权以用于使用目的。 (Your logging should confirm this.)
(您的日志记录应确认这一点。)
And then, because you got only Once authorization, when you come back to the foreground you will be Not Determined again.然后,因为你只获得了一次授权,当你回到前台时,你将再次未确定。
So the takeaway is, just laugh an evil laugh and move on.所以要点是,笑一个邪恶的笑,然后继续前进。 Your background location monitoring will work, and that's all that matters.
您的后台位置监控将起作用,这才是最重要的。 Not only does it work, but as a bonus you get to present the user with the authorization alert again , which is the reason for all this change in iOS 13. Don't worry, be happy.
它不仅有效,而且作为奖励,您可以再次向用户显示授权警报,这就是 iOS 13 中所有这些更改的原因。别担心,要开心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.