iOS-info.plist 中添加定位权限

释放双眼,带上耳机,听听看~!

一般在项目中添加权限只需要看这一篇文章:iOS info.plist 中的隐私权限就够了,但是位置权限说明有点麻烦,现总结如下,方便后期使用。

定位权限一般有四个:

  • 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 文件中同时添加 NSLocationWhenInUseUsageDescriptionNSLocationAlwaysAndWhenInUseUsageDescription,只添加一种好像是不谈出权限弹框
位置弹框如下:

位置权限弹框.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 [`NSLocation<wbr>Always<wbr>And<wbr>When<wbr>In<wbr>Use<wbr>Usage<wbr>Description`](apple-reference-documentation://hspmGRevlx) to your app’s `Info<wbr>.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`.

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

人已赞赏
iOS文章

FMDB-查看表是否存在

2020-5-11 0:48:07

iOS文章

iOS真机和模拟器静态库framework合并

2020-5-11 2:03:04

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索