在后台模式下使用iOS模拟器中的高速公路行驶/城市运行
我试图利用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];
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并在开始更新位置之前询问用户之后,我的问题就解决了。:)