ios定位权限plist_iOS-info.plist 中添加定位权限

本文详细介绍了在iOS和macOS应用中添加定位权限所需的NSLocation相关键值,包括NSLocationWhenInUseUsageDescription、NSLocationAlwaysAndWhenInUseUsageDescription、NSLocationUsageDescription和NSLocationAlwaysUsageDescription的使用场景和官方解释,以及如何处理不同iOS版本的兼容问题。
摘要由CSDN通过智能技术生成

一般在项目中添加权限只需要看这一篇文章:https://www.jianshu.com/p/2a309504cec8 就够了,但是位置权限说明有点麻烦,现总结如下,方便后期使用。

定位权限一般有四个:

NSLocationWhenInUseUsageDescription

NSLocationAlwaysAndWhenInUseUsageDescription

NSLocationUsageDescription

NSLocationAlwaysUsageDescription

NSLocationWhenInUseUsageDescription :用在 iOS app上,只能用于应用在前台时需要获取用户位置的权限说明

官方解释如下:

Use this key if your iOS app accesses location information only when running in the foreground

NSLocationAlwaysAndWhenInUseUsageDescription:用在 iOS app上, 用于应用在后台时需要获取用户位置的权限说明

官方解释如下:

Use this key if your iOS app accesses location information while running in the background

我一般会在info.plist 文件中同时添加 NSLocationWhenInUseUsageDescription 和 NSLocationAlwaysAndWhenInUseUsageDescription,只添加一种好像是不谈出权限弹框

位置弹框如下:

位置权限弹框.png

NSLocationUsageDescription:用在 macOS app上,用于获取用户位置信息的权限说明

官方解释如下:

Use this key in a macOS app that accesses the user’s location information

NSLocationAlwaysUsageDescription:用在 iOS app 上,用于 iOS11 之前,应用在后台时需要获取位置权限说明,需要跟NSLocationAlwaysAndWhenInUseUsageDescription 一起添加,iOS11 之后,只添加NSLocationAlwaysAndWhenInUseUsageDescription就可以了

官方解释如下:

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`](apple-reference-documentation://hspmGRevlx) 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 assocated with `NSLocationAlwaysAndWhenInUseUsageDescription`.

先记录这些,感谢阅读,如有错误,不吝赐教!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值