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

一般在项目中添加权限只需要看这一篇文章: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 文件中同时添加 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`.

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容