NSInternalInconsistencyException: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'
Asked Answered
D

10

51

I'm trying to get my app working in Xcode 7 beta but I'm hitting this exception:

NSInternalInconsistencyException: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'

Here's the callstack:

0   CoreFoundation                      0x00000001063a89b5 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000105e20deb objc_exception_throw + 48
2   CoreFoundation                      0x00000001063a881a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x00000001036f8b72 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4   CoreLocation                        0x00000001031c7fe3 CLClientGetCapabilities + 8270
5   peach                               0x00000001020c0ee9 -[PeachesBatteryOptimizer initWithDelegate:] + 761
6   peach                               0x0000000102086d25 -[PeachAgent init] + 1141
7   peach                               0x000000010208682c __23+[PeachAgent instance]_block_invoke + 76
8   libdispatch.dylib                   0x00000001068604bb _dispatch_client_callout + 8
9   libdispatch.dylib                   0x000000010684bedc dispatch_once_f + 543
10  peach                               0x00000001020867bb +[PeachAgent instance] + 139
11  peach                               0x0000000102086f4d +[PeachAgent createInstanceWithAppKey:andInternal:useDevApi:] + 93
12  peach                               0x0000000101e2b710 -[ABCAppDelegate createPeachAgent] + 368
13  peach                               0x0000000101e28703 -[ABCAppDelegate application:didFinishLaunchingWithOptions:] + 243
...

Screenshot

Has anyone seen this on iOS 9 beta 5?

Dibble answered 14/8, 2015 at 0:25 Comment(1)
Seen on any iOS 9. It's just an assert, actually helpful.Lorola
L
103

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 and NSLocationWhenInUseUsageDescription
Lorola answered 18/8, 2015 at 21:15 Comment(1)
#30808692Lorola
W
40

Just select your app scheme and go to Capabilities as per my picture below everything should work fine.

enter image description here

Who answered 19/7, 2018 at 19:24 Comment(1)
My app was working fine until I upgraded to Xcode 14.1. The upgrade wiped out the above settings.Operculum
G
20

I had similar issue. Below are steps to fix this crash issue (using Xcode 11.3).

  1. Add Privacy - Location usage description in Info.plist of your project.

Step 1

  1. Add Background Modes as Capability in your Project Target.

Step 2

  1. Select Location Update option

Step 3

Gyronny answered 12/5, 2020 at 11:39 Comment(0)
P
10

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];
        }
    }
}
Primateship answered 22/10, 2015 at 8:56 Comment(0)
N
5

I faced same issue on Hybrid app.

I have enabled background mode ON.

Apple has rejected my app. Saying there is no features for background mode.

So I made following changes on "BackgroundGeolocationDelegate.m"

  1. locationManager.allowsBackgroundLocationUpdates = NO;

  2. Then:

    if (authStatus == kCLAuthorizationStatusNotDetermined) {
        if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {  //iOS 8.0+
            NSLog(@"BackgroundGeolocationDelegate requestAlwaysAuthorization");
            [locationManager requestWhenInUseAuthorization];
        }
    }
    

There was no more crash.

Note: Fix is only for hybrid app

Neper answered 4/4, 2017 at 6:50 Comment(0)
L
3

Other option: If you have selected background modes in targets -> Capabilities, make sure you have any of the backgound options selected. You tell Xcode that you're going to use something in the background, but then you do not tell it what you're going to use

Leede answered 25/3, 2017 at 15:44 Comment(0)
L
2

We have iOS App & Notification Widget + Watch App. Following code does not reside in Watchkit Extension just anywhere else:

#if !EXTENSION
    self.startUpdatingLocationAllowingBackground()
#endif

We don't need to to query location or other business requirements, that are base for this app's overall setup in all domains (not just ADP/iTC).

Lorola answered 20/5, 2016 at 23:22 Comment(0)
T
2

We need to add UIBackground Mode capabilities. In my case CLLocation manager is working in background mode and I checked Location Updates key which is added into Info.plist.

Tugman answered 10/8, 2017 at 9:28 Comment(0)
S
1

This happened to me as well. Instead of putting the background capability to on and potentially getting denied by apple since you don't need background locations take out all remnants to background locations. Odds are you copied and pasted the location function from an older app or maybe off a website, not that anyone does that. Anyway.

You need to comment or completely take out: This is probably in your locationmanager function.

//for use in background
self.locationManager.allowsBackgroundLocationUpdates = true

Also in your view did load and or view will appear, you need to comment or take this out as well

//for use in background
self.locationManager.requestAlwaysAuthorization()

If you leave these in when the function is called the app will complain the capability is not turned on.

Said answered 3/5, 2017 at 13:50 Comment(0)
I
1

Another case when we can get this error is: when running unit tests.

Let's say you use CoreLocation location manager in your app. You enable location for backgroundMode, and set .allowsBackgroundLocationUpdates for location manager at some point.

If you run unit tests and in the test cases .allowsBackgroundLocationUpdates value setting is invoked anywhere in the stack, then it will crash.

Solution:

guard .allowsBackgroundLocationUpdates invocation with a test environment check:

...
guard ProcessInfo.processInfo.environment["XCTestConfigurationBlahBlah"] == nil else {
     return
}
locationManager.allowsBackgroundLocationUpdates = true
...
Integrant answered 2/10, 2022 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.