Using freeway drive/ city run in iOS simulator in background mode

喜你入骨 提交于 2019-12-12 23:55:14

问题


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

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.


回答1:


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.

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

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

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

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

Taken from this post.



来源:https://stackoverflow.com/questions/26777246/using-freeway-drive-city-run-in-ios-simulator-in-background-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!