1

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.

Amit
  • 1,043
  • 1
  • 10
  • 32

1 Answers1

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.

Community
  • 1
  • 1
Amit
  • 1,043
  • 1
  • 10
  • 32
  • Thank you! I knew what I needed was something similar to this, so after adding those entries into the plist and asking the user before I started updating the location my problem is solved. :) –  Nov 12 '14 at 18:06