在后台模式下使用在iOS模拟器中运行的高速公路驱动器/城市

编程入门 行业动态 更新时间:2024-10-23 05:53:09
本文介绍了在后台模式下使用在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 :

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

  • 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模拟器中运行的高速公路驱动器/城市

    本文发布于:2023-10-29 08:11:15,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1539174.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:驱动器   高速公路   后台   器中   城市

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!