4

While working with APNS, I was able to have push notifications work flawlessly while device is online.

For any APNS push I send while device is offline, only the last one is received once the device is back online. This seems to be coherent with Apple's Store-and-Forward design.

However - I did notice, that when sending WhatsApp messages to an offline device, once this device goes online it receives all push notifications (one for each message). This is not something based on collapse identifier, but rather independent push notification for each message.

So how did WhatsApp do it?

Tried using Notification Extension and attempt to post multiple local notifications, but this also fails as extensions are not allowed to do that.

sahar
  • 350
  • 2
  • 15
  • 1
    See https://stackoverflow.com/questions/32138687/how-does-whatsapp-receive-multiple-notification-when-apns-stores-only-one-in-cas?rq=1 – Peter Parker May 07 '20 at 06:14
  • The answers in that post refer to PushKit (voip push notification), which since iOS 13 must handle a call and cannot be used for a purpose such as chat message (see here: [link](https://developer.apple.com/documentation/pushkit/responding_to_voip_notifications_from_pushkit)). Other answers refer to background push which again is limited to be received only several times an hour. – sahar May 07 '20 at 15:03
  • Although the post was a while ago, had you found a solution? We are facing the same problem and are actually using Local Notifications via the Notification Service Extension. This seems to work but I wonder how stable it is when you have poor signal and would need to reload many messages for example. – Chris Jan 17 '23 at 08:54

1 Answers1

0

Instead of a normal push notification, use a Background Notification, which will not show anything visible, but wake up your app in background. Use this event, to make api call, get relevant data and generate multiple local notifications.

Note the following from the documentation when you implement application(_:didReceiveRemoteNotification:fetchCompletionHandler:) :

  • system calls this method when your app is running in the foreground or background
  • system does not automatically launch your app if the user has force-quit it
  • you must call the block in the handler parameter (fetchCompletionHandler) or your app will be terminated. Your app has up to 30 seconds of wall-clock time to process the notification and call the specified completion handler block
  • Apps that use significant amounts of power when processing remote notifications may not always be woken up early to process future notifications

Please read relevant documentation completely before making ANY assumptions about how you think this should work.

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58
  • I've looked into Background Notification before, and the deal breaker is this part: "The system treats background notifications as low priority: you can use them to refresh your app’s content, but the system doesn’t guarantee their delivery. In addition, the system may throttle the delivery of background notifications if the total number becomes excessive. The number of background notifications allowed by the system depends on current conditions, but **don’t try to send more than two or three per hour.**" This won't work in a scenario such as chat messages that can be much more frequent – sahar May 04 '20 at 21:07