6

On iOS 12.2 my app is terminated just after startup, with this message in xcode:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _alwaysRunsAtForegroundPriority.'

Anyone who can point me in the right direction for this one? I see that there has been some warnings about this earlier:

How to resolve app validation "The app references non-public selectors in Payload/MyApp.app/MyApp: _setAlwaysRunsAtForegroundPriority:"?

The answer to that post is that it's a security warning from webview that can be ignored. But when it's crashing my app, it can't really be ignored anymore :)

Thanks in advance for any help.

Lars

Update Feb 2nd 2019: It looks like it's the cordova-plugin-background-mode that causes the error. But i must admit that i have no idea how to fix that. It works when i remove that plugin from my project. But i need that plugin, or at least the background-mode functionality, so i need to fix this, somehow.

Update Feb 5th 2019: @coderroggie: I also have the version 2.3.2 of the cordova-plugin-ionic-webview plugin. It's strange that it works for me only when removing the cordova-plugin-background-mode (version 0.7.2)

I'll post my ionic info, if that can provide you with any helpful information.

Ionic:

ionic (Ionic CLI) : 4.9.0 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.1

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : ios 4.5.5 Cordova Plugins : cordova-plugin-ionic 5.2.9, cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.2, (and 22 other plugins)

System:

ios-deploy : 1.9.2 NodeJS : v8.11.1 (/usr/local/bin/node)
npm : 6.4.1 OS : macOS Mojave Xcode : Xcode 10.1 Build version 10B61

Update Feb 2nd (again)

My plugins:

cordova-android-firebase-gradle-release 1.0.2 "cordova-android-firebase-gradle-release"
cordova-android-play-services-gradle-release 1.4.3 "cordova-android-play-services-gradle-release"
cordova-android-support-gradle-release 1.4.4 "cordova-android-support-gradle-release"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-background-mode 0.7.2 "BackgroundMode"
cordova-plugin-badge 0.8.7 "Badge"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-customurlscheme 4.3.0 "Custom URL scheme"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-ionic 5.2.9 "cordova-plugin-ionic"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.3.2 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification"
cordova-plugin-mauron85-background-geolocation 3.0.0-alpha.49 "CDVBackgroundGeolocation"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-safariviewcontroller 1.5.4 "SafariViewController"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-vibration 3.1.0 "Vibration"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-support-google-services 1.1.0 "cordova-support-google-services"
cordova.plugins.diagnostic 4.0.7 "Diagnostic"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-push 2.1.3 "PushPlugin"

larschla
  • 377
  • 1
  • 6
  • 15

6 Answers6

5

In the plugin there's a 'setValue' towards the bottom that nukes the app. Got a build going for 12.2. Try

ionic cordova plugin add https://github.com/iowayankee/cordova-plugin-background-mode.git

package.json

    "cordova-plugin-background-mode": "git+https://github.com/iowayankee/cordova-plugin-background-mode.git",

config.xml

    <plugin name="cordova-plugin-background-mode" spec="git+https://github.com/iowayankee/cordova-plugin-background-mode.git" />

Hopefully helps someone at least get the build going

iowayankee
  • 51
  • 1
  • or just remove line [obj setValue:[NSNumber numberWithBool:YES forKey[APPBackgroundMode wkProperty]]; in APPBackgroundMode.m with the existing plugin – david valentino Apr 15 '19 at 03:22
  • it got erro after install above command:Failed to fetch plugin https://github.com/iowayankee/cordova-plugin-background-mode.git via registry. Probably this is either a connection problem, or plugin spec is incorrect. – Kapil Soni May 28 '19 at 07:34
  • @larschla, you really should try iowayankee's fork as linked here.. I've gone through about 6 different forks of `cordova-plugin-background-mode` and this is the only one that I got working on both iOS 12.3 and Android 8.1. :) –  Jul 18 '19 at 09:40
  • Nothing changed – Makarenko_I_V Aug 03 '19 at 16:10
  • Thank you. This fix the issue for me. – Venkat Kotra Sep 12 '20 at 18:47
3

Try this. Download plugin cordova-plugin-background-mode or cordova-plugin-better-background-mode in your local folder, attach it to project as a local plugin. Go to plugin file src\ios\APPBackgroundMode.m and replace following lines

+ (NSString*) wkProperty
{
    NSString* str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ==";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

with

+ (NSString*) wkProperty
{
    NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
  • I don't think this is a good solution if the intention is to release to the App Store. It looks like this is just a way to hide that it's using a private API, and one which may have changed names (because it's a private API and Apple will change those without concern for backwards compatibility). – Chris J Mar 25 '19 at 13:36
  • 1
    This method is a total hack! It's not a surprise it stopped working – Rubycon Mar 26 '19 at 12:42
2

I had a similar issue with our ionic 3 app crashing on startup with the iOS beta 12.2. I also have the latest release of cordova-plugin-background-mode.

I fixed my issue by upgrading to version 2.3.2 of the cordova-plugin-ionic-webview plug-in.

Try that. If it doesn’t fix it, please post your plugins and versions so I can compare.

Update Feb 5th, 2019
I screwed up answering earlier. I'm currently using cordova-plugin-better-background-mode@0.7.5 which is a fork of cordova-plugin-background-mode@0.7.2.

Try switching to that one. If that doesn't work I'll post the rest of the differences that we might have.

coderroggie
  • 870
  • 12
  • 25
  • I did try that, but i still get the same error. Thanks, though :) – larschla Feb 05 '19 at 18:53
  • For some reason the cordova-plugin-better-background-mode shows up as cordova-plugin-background-mode when running ionic cordova plugin ls – larschla Feb 05 '19 at 20:34
  • @larschla - Yes, it does. I don't believe it is a bonafide plugin, more of a patch/workaround for some issues with the other plugin which hasn't been updated in a while. Also, I'm now seeing the same error that you are seeing "(NSKeyValueCoding) setValue:forKey:]" and am attempting to debug. Not sure what I had setup differently to allow it to build and run... – coderroggie Feb 05 '19 at 20:36
  • Oh joy ;) Then it's not just me. If i had any clue about editing plugins i could probably fix it. Sadly, i don't. – larschla Feb 05 '19 at 20:51
  • This looks relevant. Not very helpful. https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/286 – coderroggie Feb 05 '19 at 21:14
  • Yeah. I saw that one too, but it didn't get me very far. Anyway - bedtime here in Norway now. I'll have to look more into this tomorrow. Thanks so far, anyway :) – larschla Feb 05 '19 at 21:22
  • This one seems like it's onto something. https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/293#issuecomment-460822773 I've tried that, but for some reason i still get the same error. I've removed the iOS project and added it again, and done a full code search for the string _alwaysRunsAtForegroundPriority, without finding any - still xcode tells me: 'this class is not key value coding-compliant for the key _alwaysRunsAtForegroundPriority.' I don't understand where it gets if from. Would you try doing as suggested in the link mentioned, and see if it works for you? – larschla Feb 06 '19 at 06:52
  • Tried and failed with the same results. Think I'm in a little over my head on this one. – coderroggie Feb 06 '19 at 18:44
  • Yeah. We've decided to drop the background-mode plugin, and implement the needed functionality in a different way. Thanks, though - for trying. IF i or some reason should find a solution to this, I'll let you know here. Thanks! – larschla Feb 06 '19 at 18:46
1

To find which of the plugins you use is causing the error run:

cd %HOME%/src/myProject    
grep -r "_alwaysRunsAtForegroundPriority" node_modules

Once you find it, look for an upgrade that solves the problem or replace it with an alternate plugin.

In our case, the plugin was WKWebView. A quick search on google found they had an error and fixed it. We upgraded the plugin and it worked smoothly.

mikelin
  • 376
  • 3
  • 10
0

I think your basic issue is you're running in a WKWebView, which isn't allowed to run in the background reliably. I'm facing a similar issue, and I'm afraid the best short-term solution I could come up with was to use UIWebView. UIWebView isn't a good long-term solution because it's marked as deprecated now. It looks like you're not using Ionic 4 yet, which is really good in this case. I think you can remove the 2 ionic plugins, use cordova@6.5.0 and cordova engine ios 4.5.4. Hopefully, then, when running in Xcode, everything will work and you'll see a message towards the beginning about "Using UIWebView". This issue is part of the evidence I've found that WKWebView isn't expected to work in the background: https://issues.apache.org/jira/browse/CB-10657 https://issues.apache.org/jira/browse/CB-11561

Chris J
  • 121
  • 1
  • 4
-1

This helped me: "Deployment info main interface must be empty" source: https://forum.ionicframework.com/t/app-crashes-when-i-try-to-open-in-it-on-tesflight-on-a-iphone/21005/3

stihl
  • 383
  • 3
  • 10