Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在后台模式下使用iOS模拟器中的高速公路行驶/城市运行_Ios_Ios Simulator_Core Location_Cllocationmanager - Fatal编程技术网

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

在后台模式下使用iOS模拟器中的高速公路行驶/城市运行,ios,ios-simulator,core-location,cllocationmanager,Ios,Ios Simulator,Core Location,Cllocationmanager,我试图利用iOS模拟器中的选项:调试->高速公路驾驶/城市运行,以模拟位置更新 在我的代码中,我使用CLLocationManager获取具有以下代码的位置更新: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. locationManager = [[CLLocationManager alloc] init];

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

在我的代码中,我使用
CLLocationManager
获取具有以下代码的位置更新:

- (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);
}
当我的应用程序在后台并且我在模拟器中选择该选项时,我永远不会收到代表位置更新的回调


我已经为我的应用程序提供了位置更新的后台模式。请告诉我如何准确使用这些功能,或者我是否遗漏了任何内容。

我终于解决了问题。模拟器的选项工作得非常好,但问题出在
CLLocation
的实现上

在iOS 8上,位置更新代码将不起作用,除非:

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

  • 要使位置代码正常工作,您需要添加“询问用户权限”:

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

  • 摘自。

    谢谢!我知道我需要的是类似的东西,所以在将这些条目添加到plist并在开始更新位置之前询问用户之后,我的问题就解决了。:)