ios

iOS中定位权限

2018-08-29  本文已影响177人  Jack小麻雀_

最近因为info.plist中定位权限的问题被苹果拒绝,说我没有用到Always访问定位的功能,info.plist中却写了这个属性而拒绝了我。所以就仔细查看了文档+自己实验。

项目的需求就是单次定位,如果你的需求也是只要单次定位可以直接看我实验的结果,在info中有这两条权限就可以了,不建议在此写出不必要的权限申请,可能会因此导致被拒绝。

需要的权限

对了,后边请求权限的原因请不要像我一样写,这样写的话提交肯定会因为5.1.1被拒绝,说你描述的一点都不详细~请一定详细详细详细描述。

下面是实验过程,只写Privacy - Location When In Use Usage Description控制台打印结果如下 控制台打印结果

希望能够对你有帮助,下面的是Xcode中关于Core Location(定位相关)的开发者文档,仔细读下来也很有收获。

以下是摘自Xcode中开发者文档Core Location

The type of authorization (“when-in-use” or “always”) that you request determines which location services your app can access and when it can use them.
请求权限分为“when-in-use” 和 “always”两种,这两种权限决定你的app可以使用哪种定位方式以及什么时候可以使用。

When-in-use authorization. Your app can use most services but cannot use services that automatically relaunch the app. Your app must always start services while running in the foreground. If you enable the background location capability for your app, a suspended app will wake in the background to handle location events. However, if your app is not running, it will not be launched.

When-in-use模式:你的app无法使用自动重新启动(载入?)功能。app只有在前台运行中才能定位。如果你激活了background location capability,app被挂起在后台可以被唤醒来处理定位事件,然而,如果你的app根本没有被开启过,app无法自动运行;

Always authorization. Your app can use all location services, and it can start those services from either the foreground or the background. If a location-related event occurs when your app is not running, the system launches your app and delivers the event.

Always 模式:你的app可以使用所有的定位服务(下面会列出所有的定位服务),而且无论app处在前台或后台状态都可以开始这些服务。如果发生一个定位相关的事件,系统会运行你的app并传送数据到app中。

上一篇 下一篇

猜你喜欢

热点阅读