且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS8位置:在用户授予“何时使用”后,如何请求始终授权?授权?

更新时间:2022-12-30 09:22:09

你是对的,如果用户已授予何时使用权限,则调用 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: