4

From what I've learned, silent push notifications do not call application:didReceiveRemoteNotification:fetchCompletionHandler: when the user killed the app via multitasking UI. But when looking at WhatsApps behavior, I do not understand how they manage to do the following:

  • mute a channel
  • force quit WhatsApp
  • receive a message in the muted channel
  • badge is shown
  • what's even more surprising =>
  • without launching WhatsApp, start Airplane mode
  • now launch WhatsApp => the text is shown at the right place

this means that WhatsApp somehow manages it to handle the receiption of the push notification although the app is killed. Does anyone have an idea how? With .badge, .alert, ...?

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • Silent push notifications do indeed call the `application:didReceiveRemoteNotification:fetchCompletionHandler:` method. [Check out this link](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_updates_to_your_app_silently). It says that the system wakes your app in the background and gives you 30 seconds to perform any tasks – Pranay Sep 24 '18 at 14:58
  • but that's only if the app is in the background, not if the app is killed (force quit) by the user. – swalkner Sep 24 '18 at 15:04
  • Even if the user force quits the app, I believe it should wake your app in the background mode as long as you set `remote-notification` value for `UIBackgroundModes` key in your plist. I remember this from working on an application last year. Unfortunately I can't test it now since it was a past client that I no longer work for. – Pranay Sep 24 '18 at 15:26
  • Are you **tapping on the notification** and then seeing the text in the app? Or even if you force-quit the and **don't** tap on the notification (rather tapping on app icon) it still captures the text? If it's the latter then I'm guessing it's due to WhatsApp using PushKit because it's a Voip app (the badgeCount gives me more reason to think it's because fo voip) Voip rules are different from push notification rules. See [here](https://stackoverflow.com/a/19202487/5175709). – mfaani Sep 24 '18 at 15:45
  • Note1: You never know what WhatsApp is doing when you mute a channel. I'd test it differently see [here](https://stackoverflow.com/questions/44442192/should-i-update-my-app-upon-receiving-payload-or-i-should-always-update-it-by-a). I did 1. Turned off Wifi, but kept cellular data on 2. Disabled the app's access to Cellular data 3. Then I had someone send me a message 4. Note2: I **didn't** turn off notifications, since notifications are managed at the OS level (not the app level) they were still coming through. Note3: I'm not sure if when I conducted my tests WhatsApp was having voip or not. – mfaani Sep 24 '18 at 15:45
  • @swalkner, have you managed to find the answer for this question, I am struggling for the exact answer??? – Shubham1164 Apr 01 '19 at 01:43

1 Answers1

1

There are other methods to update your application. One other way is using background app refresh. Background App Refresh lets your app run periodically in the background so that it can update its content.

--Edit for adding other possible methods:--

An other way that can be used for a short period(fixed length time) after the app has been killed is by asking for background execution time. This can give the app more running time.

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background. For example Apps that support Voice over Internet Protocol (VoIP) or Apps that Acts as a Bluetooth LE accessory.

--Edit #2 --

It seems from the info.plist of the WhatsApp application that it uses multiple UIBackgroundModes, any of them can be used to wake/keep the app in the background.

portion of info.plist of the WhatsApp:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
    <string>fetch</string>
    <string>remote-notification</string>
    <string>voip</string>
</array>
Christos Koninis
  • 1,499
  • 1
  • 15
  • 28