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

拟墨画扇 提交于 2019-11-29 02:56:44

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

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

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

kalyan711987

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

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

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.

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

dkurfirst

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!