700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > ios定位权限plist_iOS-info.plist 中添加定位权限

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

时间:2018-07-22 04:40:51

相关推荐

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

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。