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

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

我试图让我的应用程序在 Xcode 7 beta 中运行,但我遇到了这个异常:

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

调用栈如下:

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

有人在 iOS 9 beta 5 上看过这个吗?

我通过做这两件事设法解决了这个问题:

  • UIBackgroundModes 'location' 添加到 Info.plist
  • 已将 NSLocationAlwaysUsageDescription 添加到 Info.plist

从 iOS 11 开始,键被命名为:

  • NSLocationAlwaysAndWhenInUseUsageDescriptionNSLocationWhenInUseUsageDescription

如果你像我一样想在单独的项目模块/静态库中使用 [CLLocationManager setAllowsBackgroundLocationUpdates:],这是另一个解决方案。如果使用 module/library 的应用程序没有位置背景功能,您将遇到此崩溃...我采用以下方法来确保调用安全:

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

我们有 iOS 应用和通知小部件 + 手表应用。以下代码不在 Watchkit Extension 中的其他任何地方:

#if !EXTENSION self.startUpdatingLocationAllowingBackground() #endif

我们不需要查询位置或其他业务需求,这是此应用在所有域(不仅仅是 ADP/iTC)中的整体设置的基础。

其他选项:如果您在目标 -> 功能中选择了背景模式,请确保您选择了任何背景选项。 您告诉 Xcode 您将在后台使用某些东西,但没有告诉它您将要使用什么

我在混合应用程序上遇到了同样的问题。

我已启用后台模式。

Apple 拒绝了我的应用。说没有后台模式的功能。

所以我在 "BackgroundGeolocationDelegate.m"

上进行了以下更改

1.locationManager.allowsBackgroundLocationUpdates = NO;

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

没有再发生崩溃。 注意 *:修复仅适用于混合应用程序

这也发生在我身上。不要将后台功能打开并可能被苹果拒绝,因为您不需要后台位置,而是将所有残余物取出到后台位置。很可能是您从旧应用程序或网站上复制并粘贴了位置功能,而不是有人这样做。不管怎样

您需要评论或完全删除: 这可能在您的 locationmanager 函数中。

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

同样在您的视图中加载和/或视图将出现, 您也需要评论或将其删除

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

如果您在调用该函数时保留这些,应用程序将抱怨该功能未打开。

我们需要添加 UIBackground Mode 功能。 在我的例子中,CLLocation 管理器在后台模式下工作,我检查了添加到 Info.plist.

中的 Location Updates

只需 select 您的应用方案并按照我下面的图片转到“功能”,一切都应该可以正常工作。

我有类似的问题。以下是解决此崩溃问题的步骤(使用 Xcode 11.3)。

  1. 在项目的 Info.plist 中添加 Privacy - Location usage description

  1. 在您的项目目标中添加 Background Modes 作为 Capability

  1. Select Location Update 选项