iOS8中的定位服务

My app that worked fine in iOS 7 doesn't work with the iOS 8 SDK.

CLLocationManager doesn't return a location, and I don't see my app under Settings > Location Services either. I did a Google search on the issue but nothing came up, what could be wrong?

我的应用在iOS7上运行得好好的,但是到了iOS8上就出问题了.

在iOS8中,CLLocationManager并没有返回一个地址,而且,我也没有在Settings>Location Services中找到该服务,在Google上也没查到类似的问题,请问到底哪里出问题了?

I ended up solving my own problem.

Apparently in iOS 8 SDK, requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (location only when foreground) call on CLLocationManager is needed before starting location updates.

There also needs to be NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist with a message to be displayed in the prompt. Adding these solved my problem.

Hope it helps someone else.

最后我解决了这个问题.

在iOS8的sdk中,你需要额外的requestAlwaysAuthorization(用作后台定位)以及requestWhenInUseAuthorization(用作前台定位),在调用CLLocationManager更新地址之前你都需要调用上述两个方法.你还需要在Info.plist文件中额外的添加NSLocationAlwaysUsageDescription以及NSLocationWhenInUseUsageDescription,这么做了之后才解决了我的问题.

According to the Apple docs:

https://developer.apple.com/library/prerelease/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization

As of iOS 8, the presence of a NSLocationWhenInUseUsageDescription or a NSLocationAlwaysUsageDescription key value in your app's Info.plist file is required. It's then also necessary to request permission from the user prior to registering for location updates, either by calling [self.myLocationManager requestWhenInUseAuthorization] or [self.myLocationManager requestAlwaysAuthorization] depending on your need. The string you entered into the Info.plist will then be displayed in the ensuing dialog.

If the user grants permission, it's business as usual. If they deny permission, then the delegate is not informed of location updates.

根据苹果的官方文档:

https://developer.apple.com/library/prerelease/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization

在iOS8上,你需要在你的plist文件中添加新的键值NSLocationWhenInUseUsageDescription或者NSLocationAlwaysUsageDescription.然后,每次定位的时候你都需要获取用户的授权信息,通过调用[self.myLocationManager requestWhenInUseAuthorization] 或者[self.myLocationManager requestAlwaysAuthorization],至于调用哪一个,这就根据你自己的需求了.那个你添加进plist文件中的键值信息会在确认的信息中有提示.

如果用户允许你定位,你可以像往常那样子使用定位功能.如果他们拒绝了,那么,这个定位的更新更能永远也不会被执行.

iOS8中的定位服务的更多相关文章

  1. iOS开发手记-iOS8中使用定位服务解决方案

    问题描述: 在iOS8之前,app第一次开始定位服务时,系统会弹出一个提示框来让用户选择是否允许使用定位信息.但iOS8后,app将不会出现这个弹窗.第一次运行之后,在设置->隐私->定位 ...

  2. iOS8 无法设置定位服务

    针对iOS8系统,需要在plist文件中添加这两个参数 NSLocationAlwaysUsageDescription = YES NSLocationWhenInUseUsageDescripti ...

  3. IOS定位服务的应用

    IOS定位服务的应用 一.授权的申请与设置 二.定位服务相关方法 三.定位服务代理的相关方法 四.定位服务获取到的位置对象 五.航标定位得到的航标信息对象 IOS定位服务的应用 一.授权的申请与设置 ...

  4. 【Android】18.1 利用安卓内置的定位服务实现位置跟踪

    分类:C#.Android.VS2015: 创建日期:2016-03-04 一.安卓内置的定位服务简介 通常将各种不同的定位技术称为位置服务或定位服务.这种服务是通过电信运营商的无线电通信网络(如GS ...

  5. iOS8中定位服务的变化(CLLocationManager协议方法不响应,无法回掉GPS方法,不出现获取权限提示)

    最近在写一个LBS的项目的时候,因为考虑到适配iOS8,就将项目迁移到Xcode6.0.1上,出现了不能正常获取定位服务权限的问题. self.manger = [[CLLocationManager ...

  6. 解决在iOS8环境下,当用户关闭定位服务总开关时,无法将APP定位子选项加入定位权限列表的问题

    关键点:- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizati ...

  7. 在iOS8下使用CLLocationManager定位服务需要系统授权

    最近在ios8.0使用CLLocationManager定位服务,发现老不能定位,查看设置菜单中的项也是处于未知状态.想起之前都有一个弹出框提示用户是否允许定位,这次一直没有出现了.原来ios8.0下 ...

  8. 系统定位在iOS8中的改变

    CLLocationManager这个系统定位的类在iOS8之前要实现定位,只需要遵守CLLocationManagerDelegate这个代理即可: - (void)startLocate {   ...

  9. iOS8中使用CoreLocation定位[转]

    本文转自:http://blog.devzeng.com/blog/ios8-corelocation-framework.html iOS8以前使用CoreLocation定位 1.首先定义一个全局 ...

随机推荐

  1. springweb flux 服务器推送事件

    以前做服务器推送一般用轮询,后端主动给客户端推送不是很好解决.有时候也可以采用websocket 现在看了springwebflux,用它自带的方法做服务器推送方便多了. 代码如下: import o ...

  2. C语言----<另类>神奇的"Hello World!"

    先上代码 #include <iostream> using namespace std; void a() { printf("Hello World!"); } v ...

  3. BATJ面试必会之并发篇

    一.线程状态转换 新建(New) 可运行(Runnable) 阻塞(Blocking) 无限期等待(Waiting) 限期等待(Timed Waiting) 死亡(Terminated) 二.使用线程 ...

  4. VS2013 项目项目安装和部署

    版权声明:本文为博主原创文章,未经博主允许不得转载. 1.release 模式下生成项目 2.解决方案   右键  添加   新建项目 其他项目类型 安装和部署 3.操作前将待打包项目发布路径指向上述 ...

  5. mysql 用存储过程和函数分别模拟序列

    在其他大部分DBMS里都有序列的概念,即Sequence或Generator. 而mysql里没有,但有时真的很有用.下面分别用存储过程和函数来模拟序列,并用程序模拟并发场景来测试原子性和完整性,是否 ...

  6. [转]ORA-28001: the password has expired解决方法

    本文转自:http://blog.csdn.net/btt2013/article/details/54862420 参考文献:http://www.zhetao.com/content259 后台报 ...

  7. Windows2012开机启动项设置

    最简单方式 开始->运行->输入shell:startup 在打开的启动文件夹中,将需要启动程序的快捷方式复制进去,完工 重启试试吧 https://blog.csdn.net/tmton ...

  8. SpringBoot(八) Caching (更新中...)

    缓存配置 在springboot的主类添加注解@EnableCaching启用缓存支持 参考文档 33. Caching spring framework >>> 8. Cache ...

  9. SpringBoot集成Jersey

    SpringBoot集成Jersey 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> & ...

  10. Eclipse中新建Java工程的三个JRE选项区别

    整理自:https://blog.csdn.net/wdjhzw/article/details/42086615 官方解释(链接) Use default JRE: When selected, t ...