在后台模式下使用在iOS模拟器中运行的高速公路驱动器/城市 [英] Using freeway drive/ city run in iOS simulator in background mode

查看:166
本文介绍了在后台模式下使用在iOS模拟器中运行的高速公路驱动器/城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图利用iOS模拟器中的选项:debug->高速公路/城市运行,以模拟位置更新。

I am trying to make use of the options within iOS simulator : debug->freeway drive/ city run in order to simulate the location updates.

在我的代码中我正在使用 CLLocationManager 通过以下代码获取位置更新:

In my code I am using CLLocationManager for getting location updates with following code:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager setDistanceFilter:20];
}

-(void)viewWillAppear:(BOOL)animated {
[locationManager startUpdatingLocation];
}

-(void)locationManager:(CLLocationManager *)lm didUpdateLocations:(NSArray *)locations{
CLLocation *location = [locations lastObject];
NSLog(@"Location returned: %f, %f Accuracy: %f", location.coordinate.latitude,  location.coordinate.longitude, location.horizontalAccuracy);
}

在我的应用程序上,我从未收到过有关该位置更新的委托回调在后台,我正在模拟器中选择选项。

I am never getting a callback on the delegate for location updates, while my app is in background and i am selecting the option in simulator.

我已为我的应用提供了后台模式以进行位置更新。请让我知道如何精确使用这些功能,或者如果我在这里缺少任何内容。

I have provided my app the background mode for location updates. Please let me know how exactly to use these features or if i am missing anything here.

推荐答案

我终于解决了这个问题。模拟器的选项运行正常,但问题出在 CLLocation 的实现上。

I finally sorted out the problem. The simulator's options are working perfectly fine but it was the implementation of CLLocation which was the problem.

在iOS 8上,除非:

On iOS 8 the location update code will not work unless :


  1. 您添加 NSLocationWhenInUseUsageDescription &将 NSLocationAlwaysUsageDescription 添加到plist,其中包含一些将提示用户的字符串值。

  1. You add NSLocationWhenInUseUsageDescription & NSLocationAlwaysUsageDescription to the plist with some string values that will be prompted to user.

您需要添加要求用户许可以使位置代码正常工作:

You need to add ask user's permission for getting the location codes to work:

 [self.locationManager requestWhenInUseAuthorization]
 [self.locationManager requestAlwaysAuthorization]


来自这篇文章

这篇关于在后台模式下使用在iOS模拟器中运行的高速公路驱动器/城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆