iOS 中位置权限选项的区别

date
Apr 8, 2020
slug
ogqmossg
status
Published
tags
iOS
summary
type
Post
 
现在隐私保护是越来越重视,获取地理位置难度+++,APP Store 在审核时容易发生因位置权限配置不对导致被拒。目前 iOS 的 info.plist 里有 4 个位置权限设置项及对应版本:
  • Privacy - Location Usage Description:iOS 6.0–8.0
  • Privacy - Location When In Use Usage Description:iOS 11.0+
  • Privacy - Location Always Usage Description:iOS 8.0–10.0
  • Privacy - Location Always and When In Use Usage Description:iOS 11.0+
以下测试分别在 iOS 的 12.3.1、13.1.2 环境下进行,下文中分别简称 iOS12、iOS13。

详细说明

1. Privacy - Location Usage Description

官网说明, 适用于 iOS 6.0–8.0,所以新项目中不再使用,写不写都无所谓。

2. Privacy - Location When In Use Usage Description

只允许使用应用期间 APP 获取地理位置,官网说明,适用于 iOS 11.0+。
在 iOS 12 中
  • 用户提示框
    • notion image
  • 设置菜单
    • notion image
在 iOS 13 中
  • 用户提示框
    • notion image
  • 设置菜单
    • notion image

3. Privacy - Location Always Usage Description 和 Privacy - Location Always and When In Use Usage Description

Privacy - Location Always Usage DescriptionPrivacy - Location Always and When In Use Usage Description,都是申请允许 APP 在前后台时都能获取地理位置,下面来看看具体区别。
先看官网的说明:
Use this key if your iOS app accesses location information in the background, and you deploy to a target earlier than iOS 11. In that case, add both this key and NSLocationAlwaysAndWhenInUseUsageDescription to your app’s Info.plist file with the same message. Apps running on older versions of the OS use the message associated with NSLocationAlwaysUsageDescription, while apps running on later versions use the one associated with NSLocationAlwaysAndWhenInUseUsageDescription. If your app only needs location information when in the foreground, use NSLocationWhenInUseUsageDescription instead. For more information, see Choosing the Location Services Authorization to Request. If you need location information in a macOS app, use NSLocationUsageDescription instead.
Use this key if your iOS app accesses location information while running in the background. If your app only needs location information when in the foreground, use NSLocationWhenInUseUsageDescription instead. For more information, see Choosing the Location Services Authorization to Request. If you need location information in a macOS app, use NSLocationUsageDescription instead. If your iOS app deploys to versions earlier than iOS 11, see NSLocationAlwaysUsageDescription.
在 iOS 13 中
  • 设置菜单
    • notion image

结论

  • 如果 app 需要前台运行定位权限,需要配置 NSLocationWhenInUseUsageDescription;
  • 如果 app 需要后台运行定位权限,需要配置 NSLocationAlwaysAndWhenInUseUsageDescription;(如果适配 iOS 11 之前版本,还需要配置 NSLocationAlwaysUsageDescription)
notion image
notion image
2020 年 05 月上架一个新包,之前按照别人文档来囫囵吞枣的把位置权限全部加上,于是收到被拒的大礼包:
notion image
后经大佬指点,被拒的真正原因是因为 xcode 11 里 Location updates 被勾选了,去掉重新提交审核就好了。
notion image
notion image

参考资料:

© 刘德华 2020 - 2023