【问题标题】:Is it possible to fallback to AuthorizedWhenInUse when a user doesn't allow AuthorizedAlways in iOS?当用户在 iOS 中不允许 AuthorizedAlways 时,是否可以回退到 AuthorizedWhenInUse?
【发布时间】:2015-08-04 17:46:56
【问题描述】:

我的应用在后台使用用户位置,但有时,用户不允许应用始终收集 GPS 数据。该应用只能处理前台位置,我想将其设置为后备。

有没有一种优雅的方式,一旦 iOS 用户拒绝了我的 AuthorizedAlways 请求,重新提示用户授予 AuthorizedWhenInUse 权限?

【问题讨论】:

  • 预先给用户两个选项。解释 AuthorizedAlways 的优点和缺点。就个人而言,如果我被要求始终使用该应用程序,我通常会丢弃该应用程序,除非我有充分的理由说明这对我有利。我实际上很重视我的隐私和更好的生活。

标签: ios permissions gps core-location


【解决方案1】:

你不能强迫它,但你可以:

1) 知道用户被拒绝权限 2) 并显示警告:“请转到设置并启用它”。
3) 进入ios设置([[UIApplication sharedApplication] openURL:[NSURL URLWithString: UIApplicationOpenSettingsURLString]];)

类似这样的:

- (void)checkLocation
{
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

    if (status == kCLAuthorizationStatusAuthorizedAlways){
        NSLog(@"ok");
    } else if(status == kCLAuthorizationStatusDenied ||
              status == kCLAuthorizationStatusAuthorizedWhenInUse){
        [self showRequestLocationMessage];
    } else if(status == kCLAuthorizationStatusNotDetermined){
        //request auth
    }

}

- (void)showRequestLocationMessage
{
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"Settings"
                                                     style:UIAlertActionStyleDefault
                                                   handler:^(UIAlertAction * alertAction){
                                                       [[UIApplication sharedApplication] openURL:[NSURL URLWithString: UIApplicationOpenSettingsURLString]];
                                                   }];

    NSString *title = @"Service Enable";
    NSString *text = @"Please enable your location.. bla bla bla";

    UIAlertController *alertController = [UIAlertController
                                          alertControllerWithTitle:title
                                          message:text
                                          preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                           style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action){
                                                             [alertController dismissViewControllerAnimated:YES completion:nil];
                                                         }];

    [alertController addAction:cancelAction];
    [alertController addAction:action];

    [self presentViewController:alertController animated:YES completion:nil];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2021-02-06
    • 2022-01-24
    相关资源
    最近更新 更多