NSInternalInconsistencyException: 'Invalid par

2019-01-24 00:16发布

问题:

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
...

Has anyone seen this on iOS 9 beta 5?

回答1:

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


回答2:

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];
        }
    }
}


回答3:

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;

  1. 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



回答4:

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



回答5:

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



回答6:

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).



回答7:

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.



回答8:

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.