ios NSInternalInconsistencyException: '无效参数不满足:!stayUp || CLClientIsBackgroundable(internal->fClient)'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32000531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSInternalInconsistencyException: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'
提问by DanielG
I'm trying to get my app working in Xcode 7 beta but I'm hitting this exception:
我正在尝试让我的应用程序在 Xcode 7 beta 中运行,但我遇到了这个异常:
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?
有人在 iOS 9 beta 5 上看到过这个吗?
回答by igraczech
I've managed to solve this by doing these two things:
我通过做这两件事设法解决了这个问题:
- added
UIBackgroundModes
'location' to Info.plist - added
NSLocationAlwaysUsageDescription
to Info.plist
- 将
UIBackgroundModes
“位置”添加到 Info.plist - 添加
NSLocationAlwaysUsageDescription
到 Info.plist
As of iOS 11, keys are named:
从 iOS 11 开始,键被命名为:
NSLocationAlwaysAndWhenInUseUsageDescription
andNSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
和NSLocationWhenInUseUsageDescription
回答by Vision Mkhabela
回答by Mete
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:
如果像我一样想[CLLocationManager setAllowsBackgroundLocationUpdates:]
在单独的项目模块/静态库中使用,这是另一种解决方案。如果使用该模块/库的应用程序没有位置后台功能,您将遇到此崩溃...我使用以下方法使调用安全:
- (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];
}
}
}
回答by 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"
所以我对“BackgroundGeolocationDelegate.m”进行了以下更改
1.locationManager.allowsBackgroundLocationUpdates = NO;
1.locationManager.allowsBackgroundLocationUpdates = NO;
if (authStatus == kCLAuthorizationStatusNotDetermined) { if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { //iOS 8.0+ NSLog(@"BackgroundGeolocationDelegate requestAlwaysAuthorization"); [locationManager requestWhenInUseAuthorization]; } }
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
没有更多的崩溃。注意*:修复仅适用于混合应用程序
回答by Spidvmp
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
其他选项:如果您在目标 -> 功能中选择了背景模式,请确保您选择了任何背景选项。你告诉 Xcode 你将在后台使用一些东西,但你没有告诉它你将使用什么
回答by Anil Gupta
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.
我们需要添加 UIBackground Mode 功能。就我而言,CLLocation 管理器在后台模式下工作,我检查了Location Updates
添加到 Info.plist 中的密钥。
回答by igraczech
We have iOS App & Notification Widget + Watch App. Following code does not reside in Watchkit Extension just anywhere else:
我们有 iOS 应用程序和通知小工具 + 手表应用程序。以下代码不存在于其他任何地方的 Watchkit 扩展中:
#if !EXTENSION
self.startUpdatingLocationAllowingBackground()
#endif
#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).
我们不需要查询位置或其他业务需求,这是此应用程序在所有域(不仅仅是 ADP/iTC)中整体设置的基础。
回答by 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.
您需要评论或完全删除:这可能在您的locationmanager功能中。
//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.
如果您在调用函数时保留这些内容,应用程序将抱怨该功能未打开。
回答by Jayprakash Dubey
I had similar issue. Below are steps to fix this crash issue (using Xcode 11.3).
我有类似的问题。以下是修复此崩溃问题的步骤(使用 Xcode 11.3)。
- Add
Privacy - Location usage description
inInfo.plist
of your project.
- 添加
Privacy - Location usage description
在Info.plist
您的项目。
- Add
Background Modes
asCapability
in your Project Target.
- 加入
Background Modes
为Capability
你的项目目标。
- Select
Location Update
option
- 选择
Location Update
选项