美文网首页OC-开发案例收集
iOS-info.plist 中添加定位权限

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

作者: 329fd8af610c | 来源:发表于2019-10-26 15:11 被阅读0次

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

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

    相关文章

      网友评论

        本文标题:iOS-info.plist 中添加定位权限

        本文链接:https://www.haomeiwen.com/subject/wdzyvctx.html