16

According to the official Apple documentation, APNS (Apple Push Notification Service) stores only the last notification if the device is offline.

Apple Push Notification Service includes a default Quality of Service (QoS) component that performs a store-and-forward function. If APNs attempts to deliver a notification but the device is offline, the QoS stores the notification. It retains only one notification per application on a device: the last notification received from a provider for that application. When the offline device later reconnects, the QoS forwards the stored notification to the device. The QoS retains a notification for a limited period before deleting it.

Then how do apps like whatsapp send messages from multiple users when the device comes online? Those messages would have been received as separate notification if device was online.

Laurentiu L.
  • 6,566
  • 1
  • 34
  • 60
crysis
  • 1,514
  • 1
  • 20
  • 35
  • just curious, as I am not a whatsapp users, what happens exactly when the device switch on: even if you don't run what's app you get all the missing notification that should have been sent during the switch off period? – tomsoft Aug 25 '15 at 08:38

2 Answers2

8

It seems like there was an update to this issue on iOS 8 that will allow your app to wake up in the background due to push even if your user manually killed it. Check this out: Wake your app in the background using PushKit in iOS8.

This means that you can send notifications to your app and once it's re-connected, it will be woken up by the operating system and will be able to communicate with your server. Then, you can implement the logic to send it all of the push messages that were missed while the device was offline.

I have to admit that I have yet to try it out myself, but it sounds like this might be the solution to the issue you're describing.

Community
  • 1
  • 1
Rony Rozen
  • 3,957
  • 4
  • 24
  • 46
  • This is the most probable explanation. Since WhatsApp also has a VoIP feature, they can use the new PushKit VoIP push notifications, which will wake the app, even if it was force quit. Then WhatsApp can sync all the unread messages and show them as local notifications. Still, I wonder, how long VoIP push notifications are stored, when the device is offline, since receiving a notification for a VoIP call that was initiated hours ago doesn't make sense to me. – Baris Akar Aug 27 '15 at 08:24
  • @Rony Rozen can you please explain it "you can send notifications to your app" how we can make it possible. – Ravi Kumar Feb 07 '17 at 06:12
  • It's an old answer but you should probably over the linked reply. Specifically, this tutorial may be helpful: https://zeropush.com/guide/guide-to-pushkit-and-voip – Rony Rozen Feb 08 '17 at 07:21
2

Since every notification you send while the device is offline effectively overwrites the existing one, you have two ways to go about this:

  • Include all messages that the device does not know about yet in every notification (so you replace a notification that contains message A with one that contains both message A and B). You may run into a maximum size limit at some point.

  • Do not include the actual messages in your notifications at all. When the application gets the notification, it can ask the server for new messages.

Jan Böcker
  • 170
  • 5
  • 1
    In first case how would the server know if previous notification is delivered or not (in order to include previous message in new notification) – crysis Aug 21 '15 at 11:44
  • The next time your application can communicate with the server, it can notify the server that it got the push-notification with messages A and B. The server needs to keep track of which messages were fetched / acknowledged by the client. Unless the apple push notifications use a communication channel that may be available at a time when your application cannot connect to the server (e.g. they use SMS but your app needs IP connectivity), the first approach has no advantages over the second, except maybe a slightly lower time to display new messages. – Jan Böcker Aug 21 '15 at 12:27
  • The problem here is, that iOS won't wake the app, if it was force quit. Then there is no way to communicate with the server, when you get a notification, it will just simply be displayed. – Baris Akar Aug 25 '15 at 08:30