iOS8位置:在用户授予“何时使用”后,如何请求始终授权?授权? [英] iOS8 Location: How should one request Always Authorization after user has granted "When In Use" Authorization?

查看:133
本文介绍了iOS8位置:在用户授予“何时使用”后,如何请求始终授权?授权?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用启动地图视图时,我请求iOS8使用中位置权限。假设用户授予该权限。

When my app launches the map view, I request the iOS8 "When In Use" location permission. Assume user grants that.

我想仅在用户选择加入我的地理围栏功能时才请求始终权限。但是调用CLLocationManager.requestAlwaysAuthorization没有任何效果,因为当前的授权状态不再是kCLAuthorizationStatusNotDetermined。

I would like to request the Always permission only when user opts-in to my geofencing feature. But calling CLLocationManager.requestAlwaysAuthorization has no effect because the current authorization status is no longer kCLAuthorizationStatusNotDetermined.

如何在用户授予使用时权限后请求始终权限?我认为这是一个常见的用例,因为除非需要,应用程序应该避免要求Always权限。

How would one go about requesting the Always permission AFTER user has granted When In Use permission? I would think this is a common use case because apps should avoid asking for the Always permission unless needed.

推荐答案

你是对的,如果用户已授予何时使用权限,则调用 requestAlwaysAuthorization 将不会执行任何操作。我使用的解决方法是将用户链接到设置屏幕,让他们自己打开始终设置。以下是执行此操作的步骤:

You are right, calling requestAlwaysAuthorization will not do anything if the user already granted 'when in use' permission. A workaround I used was to link the user to the settings screen and let them turn on the 'Always' setting themselves. Here are the steps to do that:


  1. app-Info.plist中创建新密钥调用 NSLocationAlwaysUsageDescription 并输入一些原因,说明为什么需要在值字段中请求始终权限。

  1. Create a new key in your app-Info.plist called NSLocationAlwaysUsageDescription and enter some reasons as to why you need to request the always permission in the value field.

将您的用户链接到您应用的设置屏幕(此处提供更多信息

Link your user to your app's settings screen (more info here)

NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settings])
    [[UIApplication sharedApplication] openURL:settings];


  • 用户点击链接后会看到:

  • Once the user taps your link they will see this:

    当他们点击位置时,他们将能够看到同时使用应用始终可供选择的设置:

    and when they click on Location, they will be able to see both While Using the App and Always settings to choose from:

    这篇关于iOS8位置:在用户授予“何时使用”后,如何请求始终授权?授权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆