简体   繁体   English

iOS 13 仅在用户“允许一次”后再次调用 requestAlwaysAuthorization

[英]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.

相关问题 如何在iOS 13中使用`requestAlwaysAuthorization`在CLLocationManager中请求地理位置? - How to request geolocation in CLLocationManager with `requestAlwaysAuthorization` in iOS 13? 比较iOS中的时间以允许用户再次发布 - Comparing time in iOS to allow user to post again 使用 requestAlwaysAuthorization() 后不会出现“始终允许”位置 - "Always Allow" location does not appear after using requestAlwaysAuthorization() iOS 13 如何检查用户只给定始终允许位置权限 - iOS 13 How to check user is given only Always allow location permission self.locationManager.requestAlwaysAuthorization()仅在iOS 8.0或更高版本上可用-Swift - self.locationManager.requestAlwaysAuthorization() is only available on iOS 8.0 or newer - Swift iOS模拟器崩溃requestAlwaysAuthorization() - iOS Simulator Crash requestAlwaysAuthorization() 让 UIDocumentPickerViewController 只允许在 iOS 13 上选择二进制数据文件 - Getting UIDocumentPickerViewController to only allow the selection of binary data files on iOS 13 requestAlwaysAuthorization after requestWhenInUseAuthorization被接受 - requestAlwaysAuthorization after requestWhenInUseAuthorization is accepted 是否可以仅允许基于 iOS 13 上的视图 controller 的特定方向? - Is it possible to allow only specific orientations based on view controller on iOS 13? UITableViewAlertForLayoutOutsideViewHierarchy 错误:仅警告一次(iOS 13 GM) - UITableViewAlertForLayoutOutsideViewHierarchy error: Warning once only (iOS 13 GM)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM