iOS9 not tracking location while in background

Peter Lapisu picture Peter Lapisu · Sep 24, 2015 · Viewed 14.8k times · Source

My app tracks location while in background... the location background mode is enabled and i use

[self.locationManager startUpdatingLocation];

This works great on iOS7-8 but it stopped working on iOS9

In simulator it works, but on real device i get no callback while in background... when running the same code on iOS8 device i get normal callbacks as before

Is this documented? Why does it work in simulator and not in device? is it a bug?

When using startSignificantChangeUpdates it works on iOS9, i wonder if this is some kind of battery saving feature, that they possibly prohibited startUpdatingLocation

Answer

sigsegfalt picture sigsegfalt · Nov 9, 2015

Use:

if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
    [self.locationManager setAllowsBackgroundLocationUpdates:YES];
}

to avoid using a macro that evaluates the system version. This will call setAllowsBackgroundLocationUpdates: on iOS 9 but not on iOS 8.