When observing WhatsApp, and similar chat apps, I can see the following behaviour:
- Turn off internet connection (both cellular and WIFI).
- Make sure chat app is not active (in background).
- Send multiple messages to my device (via other devices).
- Turn on internet.
- In a matter of seconds, all messages are shown as notifications.
I can reproduce this scenario every time I try.
Now I am working on my own iPhone app and I can't seem to figure out how to implement this behaviour. As far as I understand this could have been implemented in several ways:
Using the QoS feature of APNS:
I read that the QoS stores a message if it wasn't delivered to the device, and sends it again when the device reconnects. This solution, however, is not making sense because of two reasons:
QoS is said to save only one undelivered message at a time. But it my case, I get more than one message.
The messages are shown instantly, the moment as I turn the internet connection, and QoS documentation says it may take some time to get the undelivered message.
Using a background service or listen to connectivity changes:
Regarding the background service, I know the closest thing to a running background service is Background Fetch but again it dose not seem to fit here because it is periodical.
And I also wasn't able to find any callback I can hookup to, to know when connectivity had changed while I am in background, and perform some actions.
Do you have any idea how could one implement this feature for an iPhone app? (QoS? Other background APIs?)