requestWhenInUseAuthorization

requestWhenInUseAuthorization

本文介绍了Xcode 6 GM - CLLocationManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Xcode 5制作的项目。我有一个ViewController,我使用CLLocationManager获取手机位置。我已经实现了两个:

I have a project made using Xcode 5. I have a ViewController where i take the phone location using a CLLocationManager. I have implemented both:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

哪个有效大。

现在我用Xcode 6 GM打开了这个项目,这两个方法都没有被调用(不在模拟器或设备上)。

Now i opened the project with Xcode 6 GM, and neither of these 2 methods where called (not on simulator, or device).

任何想法?
谢谢

Any ideas?Thanks

推荐答案

请检查线程

你必须要处理两件事

1。


  • requestAlwaysAuthorization - 用于背景位置

  • requestAlwaysAuthorization - for background location

[self.locationManager requestWhenInUseAuthorization];

requestWhenInUseAuthorization -location仅在应用处于有效状态时

requestWhenInUseAuthorization-location only when app is active

[self.locationManager requestAlwaysAuthorization];

如果你这样做如果没有两个请求,iOS将忽略startUpdateLocation请求。

If you do not make either of two request , iOS will ignore startUpdateLocation request.

2。
在Info.plist中包含 NSLocationAlwaysUsageDescription NSLocationWhenInUseUsageDescription 键,具体取决于您要求的权限。这个字符串将由iOS显示给用户,这样用户就可以了解为什么我们的应用需要获得许可。

2.Include NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist depending upon which permission you are asking for. This string will be diaplayed by iOS to user so the user can get excat idea why does our app needs permission.

希望这会有所帮助。

这篇关于Xcode 6 GM - CLLocationManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:05