Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

Q: Any way to receive a silent push in a killed app #393

Closed zarko-tg closed 9 months ago

zarko-tg commented 9 months ago

This would apply to both Android and iOS but my observation is only for Android atm.

The API reference says:

push-receive


Push notification receive event. Is fired when application receives push notification in foreground or background. Closed applications does not receive this event.

Is there no way at all for a killed app to react to a silent push?

wfhm commented 9 months ago

@zarko-tg What do you mean by a "killed app"? Do you mean the app that is swiped from the list of apps (opened when you click Overview button) or completely terminated in Application settings?

The latter option kills all app components and it cannot respond to pushes at all, be it silent or a regular one. However, apps that are swiped from overview can still receive and handle silent and regular pushes.

For iOS, silent pushes behavior is different. All apps can receive background updates (if you enabled this background mode for your app), but it highly depends on your app's behavior score. I will try to explain it in a bit more detail:

With iOS 11, Apple introduced so-called Duet Activity Scheduler Daemon (DASD), which maintains a scored list of background activities. Periodically, it rescores each item in its list, according to various criteria such as whether it is now due to be performed.

Starting with iOS 13, especially, with iOS 13.3, silent pushes have the lowest priority for the operating system. When such push is received, iOS makes a decision to wake or not to wake the app in background, and it takes a lot of factors into account, such as CPU loads, battery level, whether device is charging or not, and even device temperature. You can clearly see it in device logs:

com.apple.pushLaunch.com.argentum.auri:54C0A4:[com.apple.pushLaunch.com.argentum.auri:54C0A4:[ 
{name: DeviceActivityPolicy, policyWeight: 5.000, response: {Decision: Can Proceed, Score: 0.50}} 
{name: ChargerPluggedInPolicy, policyWeight: 2.000, response: {Decision: Can Proceed, Score: 0.50, Rationale: [{voltage == 4278 AND temperature == 3700}]}} 
{name: ThermalPolicy, policyWeight: 5.000, response: {Decision: Can Proceed, Score: 0.60, Rationale: }} ] 
sumScores:91.510000, denominator:97.010000, FinalDecision: Can Proceed FinalScore: 0.943305}
com.apple.pushLaunch.com.argentum.auri:FC7F61:[ com.apple.pushLaunch.com.argentum.auri:FC7F61:[ 
{name: ThermalPolicy, policyWeight: 5.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{thermalLevel >= 20}]}} ], 
FinalDecision: Absolutely Must Not Proceed}

Back in 2020 we had contacted Apple support, and they confirmed that in some cases such push can be ignored:

What remains to explain this is you are indeed running into a throttle. Regardless whether a push is received by the device or not, iOS may decide to not wake up your backgrounded app at any given time.

They also said it might be a bug in the iOS, however, they have not yet confirmed or denied it since our last communication:

That said, the indication of such a throttle is quite different than what I saw in the logs you sent. The logs definitely said your app was not permitted. This could be perhaps a bug in our logging, but I don’t want to dismiss the issue that easily. Let’s keep an eye on this, and if you start seeing the issue again, please let me know, and we’ll re-open this case.

So, summing up said above, it is definitely possible to receive silent pushes received in background state, however they are not guaranteed to be handled by the OS.

I'll close this ticket for now, however please feel free to reopen it should you have additional questions

zarko-tg commented 8 months ago

Thanks for the elaborate explanation. As written previously I noticed the issue on Android. "Killed" as in swiped away from the list of active apps. My own conclusion is that we cannot rely on the event with such limitations, regardless of the operating system / version.

wfhm commented 8 months ago

@zarko-tg Apple somewhat improved silent pushes experience in latter versions, so it still might be used for background updates. However we discourage our customers from building their apps' core functionality on silent pushes.

As for Android, silent pushes should work fine - for Pushwoosh SDK they are the same as regular pushes, just with a bit different handling logics.