iOS8中的定位服务

简介:

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文件中的键值信息会在确认的信息中有提示.

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

目录
相关文章
|
7月前
|
iOS开发 开发者 MacOS
初雪云推出了全新的“iOS证书自动化服务”,欢迎体验!
我们为开发者推出了全新的“iOS证书自动化服务”!现在,您可以快速上传组织/个人苹果账号,并在线生成正式证书和测试证书。无需使用MAC OS系统,不再需要繁琐的手动证书制作流程;而且不必安装任何软件,只需在网页上即可方便的绑定测试设备UDID。这项服务能够帮助开发者轻松打包和快速测试应用,提供更全面的一站式流程服务。赶快来试试吧!
96 0
|
机器学习/深度学习 安全 测试技术
阿里云EMAS-专家测试服务iOS和Android上百种机型性能、兼容及UI等测试
阿里云EMAS测试专家有着集团内部多个日活过亿规模APP经验,提供EMAS专家测试,客户只需提交测试需求,从用例设计、脚本录制、海量机型测试、整理测试结果、48小时输出专家测试报告均由阿里云EMAS测试专家一站式服务完成。覆盖功能测试、深度兼容测试、性能测试、UI适配测试以及隐私合规检测等,帮助用户以更低成本获得高质量的全面测试能力,可用于APP正式发版前验收,规避手机APP上线前或发版过程中各类隐患。
407 0
阿里云EMAS-专家测试服务iOS和Android上百种机型性能、兼容及UI等测试
|
BI 开发工具 Android开发
和iPhone玩家对战吧,Google Play游戏服务将支持iOS平台
Google今天在游戏开发者大会上宣布了若干与Google Play游戏服务的相关更新,其中和游戏玩家关系最大的也许就是Google Play Game Services将支持iOS平台,这也就意味着回合制和实时多人游戏将同时支持Android和iOS,以后这两个平台的玩家也就可以互动了。显然,这对于游戏开放商也是个好消息——让原本被割裂的用户参与到同场竞技中来。
267 0
和iPhone玩家对战吧,Google Play游戏服务将支持iOS平台
|
传感器 定位技术 iOS开发
IOS定位服务的应用
IOS定位服务的应用
154 0
IOS定位服务的应用
|
缓存 定位技术 iOS开发
iOS 定位服务与地图
介绍iOS中CoreLocation与MapKit的基本使用
1064 0