iOS中位置权限选项的区别
2020/5/18 23:26:46
本文主要是介绍iOS中位置权限选项的区别,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
iOS中位置权限选项的区别
本文github地址:github.com/stelalae/bl…
现在隐私保护是越来越重视,获取地理位置难度+++,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中
- 用户提示框
- 设置菜单
在iOS 13中
- 用户提示框
- 设置菜单
3. Privacy - Location Always Usage Description 和 Privacy - Location Always and When In Use Usage Description
Privacy - Location Always Usage Description
和Privacy - Location Always and When In Use Usage Description
,都是申请允许APP在前后台时都能获取地理位置,下面来看看具体区别。
先看官网的说明:
- NSLocationAlwaysUsageDescription,iOS 8.0–10.0,已废弃,即兼容iOS 11以前的需要配置这个。
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.
- NSLocationAlwaysAndWhenInUseUsageDescription,iOS 11.0+,即是用来在iOS 11及以后代替
NSLocationAlwaysUsageDescription
的。
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中
- 设置菜单
结论
- 如果app需要前台运行定位权限,需要配置NSLocationWhenInUseUsageDescription;
- 如果app需要后台运行定位权限,需要配置NSLocationAlwaysAndWhenInUseUsageDescription;(如果适配iOS 11之前版本,还需要配置NSLocationAlwaysUsageDescription)
官方建议:Choosing the Location Services Authorization to Request
2020年05月上架一个新包,之前按照别人文档来囫囵吞枣的把位置权限全部加上,于是收到被拒的大礼包:
参考资料:
- iOS中各种类型的位置权限的选项有什么区别
- [资源分享] iOS定位权限请求时易犯的错误小结
这篇关于iOS中位置权限选项的区别的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-10-05Swift语法学习--基于协议进行网络请求
- 2022-08-17Apple开发_Swift语言地标注释
- 2022-07-24Swift 初见
- 2022-05-22SwiftUI App 支持多语种 All In One
- 2022-05-10SwiftUI 组件参数简写 All In One
- 2022-04-14SwiftUI 学习笔记
- 2022-02-23Swift 文件夹和文件操作
- 2022-02-17Swift中使用KVO
- 2022-02-08Swift 汇编 String array
- 2022-01-30SwiftUI3.0页面反向传值