It seems like that callbacks in Javascript are not executed properly when the app is killed (suspended) with no WKSuspendInBackground option.
I'm using phonegap-plugin-push to handle VoIP notifications. I am 100% sure that I have configured it correctly (it has been running without issues for months in production).
I'm running the following test (I never see the console.log in the console):
pushObject.on('notification').subscribe((notificationEvent: NotificationEventResponse) => {
console.log('XXX 1');
});
I can confirm that:
WKSuspendInBackground=falseWKSuspendInBackground=falseI am aware of these issues:
https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/293
https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/286
But I decided to open a new issue because this specific problem (that callbacks are not executed) was not described before.
I'm observing a similar behaviour. The JS context seems to be paused shortly after the callback was executed. So I can see the console log but after a brief time the web view seems to be paused even when the native code can still execute. This pausing might be a 'feature' of the WKWebview to prevent a website from rendering/using resources when its not displayed. It's also a really big deal for apps relying on this. Maybe I am missing something obvious. Is 'real' (not paused after a very short time) background execution on iOS in JS possible at all?
@j4nnis we had to build our own native plugin to support reliable background execution & push notification handling 😄
@BorntraegerMarc hm yes, I also implemented native Objective-C/Swift code that executes properly in the background (starts a background task etc). Just not JS in a WKWebView for any extended period of time. I wonder if this is expected behaviour for a WKWebView.
Thanks for your response, it sounds to me like it apparently is the current situation.
As a curiosity: continuously calling the JS from the native side (from a cordova call back) seems to keep the JS in the web view running and enables some background execution... I still think I must be missing something or this is just not a use-case Apple sees for Web-Views 🤷♂️😄
seems to keep the JS in the web view running and enables some background execution
Good idea. Never tried it out though.
For me the native part was more a decision to be 100% future proof. I have a feeling that background execution & push notification handling is introducing breaking changes with every iOS release😄
WKSuspendInBackground preference is back on 2.5.0 and 4.1.0 as Apple fixed the white screen problems the preference was causing. Checked that also works on iOS 13 beta.
Most helpful comment
WKSuspendInBackground preference is back on 2.5.0 and 4.1.0 as Apple fixed the white screen problems the preference was causing. Checked that also works on iOS 13 beta.