NSInternalInconsistencyException: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'
I've managed to solve this by doing these two things:
- added
UIBackgroundModes
'location' to Info.plist - added
NSLocationAlwaysUsageDescription
to Info.plist
As of iOS 11, keys are named:
NSLocationAlwaysAndWhenInUseUsageDescription
andNSLocationWhenInUseUsageDescription
Just select your app scheme and go to Capabilities as per my picture below everything should work fine.
Here's another solution if like me you want to use [CLLocationManager setAllowsBackgroundLocationUpdates:]
in a separate project module / static library. You'll get this crash if the app using that module/library doesn't have the location background capability... I made the following method to make the call safe:
- (void) setAllowsBackgroundLocationUpdatesSafely
{
NSArray* backgroundModes = [[NSBundle mainBundle].infoDictionary objectForKey:@"UIBackgroundModes"];
if(backgroundModes && [backgroundModes containsObject:@"location"]) {
if([mLocationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
// We now have iOS9 and the right capabilities to set this:
[mLocationManager setAllowsBackgroundLocationUpdates:YES];
}
}
}