2

a simple question: is it possible to get a message, notification or similar when the internet connection is available when app is killed or not running?

For my purpose, I need a way to synchronize all my notifications because APNs can send only the last message.

EDIT: I'm wondering how some apps (e.g. whatsapp) are able to sync their notifications when the internet connection is up. If I kill whatsapp, I can receive multiple notification when internet connection is reachable, but the APNS server provides only last message and, for this case, I'm not able to send silent notification. If I should develop a chat application, what are the best practices to work with Apple notifications?

CeccoCQ
  • 3,746
  • 12
  • 50
  • 81
  • You don't describe what this synchronisation includes. Also, what background capabilities have you looked at and what are you concerned about following that research? – Wain Sep 28 '15 at 15:03
  • 2
    If your app is killed, how do you expect it to run any code? – Abizern Sep 28 '15 at 15:12

1 Answers1

1
  1. If you send a push notification with a title, text, sound and/or badge property while the app is suspended (was killed / force closed), the device will still receive it, e.g. will show the text as a notification, play a sound and/or change the badge count.

  2. However, your app won't be launched or woken up in the background in this case, so you have no way to handle the notification before the user taps on it. (See this question: Will iOS launch my app into the background if it was force-quit by the user?)

So if the app was force closed by the user, your only option is to send a notification to be displayed as it is and if the device is offline, only the last notification will be received and displayed by the device.

For more control, you could use silent push notifications to implement "push-to-sync". In this case, the push notification only signals that there is new data to be fetched. The app (if not force closed) loads the data from the server then and triggers local notifications with the right data in the right order. But this won't work, if the app was force closed.

Apple push notifications have a lot of restrictions, so you won't be able to implement a perfect solution. In my opinion, it's fine if the user gets only the last notification when the device gets online after being offline for a while. At least he is informed that there is a new message and after opening the app, he can see the other new messages too. For the "push-to-sync" scenario, I would say that the user has no right to expect that the app works as desired, if he force-quits it.

Push notifications were never intended to be used in the way they are used by a lot of apps by now. E.g. they shouldn't contain sensitive data such as a chat message. They were intended to inform the user that there is new data for the app, so he can launch it to see the new data. E.g. instead of sending the actual chat message text a push notification should just contain the text "You have a new message". Then, you don't have the problem you described. Of course this is a terrible solution in terms of usability.

Community
  • 1
  • 1
Baris Akar
  • 4,895
  • 1
  • 26
  • 54
  • Hi, thanks for your response. I've understood the behaviour, but now I'm wondering how some apps (e.g. whatsapp) are able to sync their notifications when the internet connection is up. If I kill whatsapp, I can receive multiple notification when internet connection is reachable, but the APNS server provides only last message and, for this case, I'm not able to send silent notification. If I should develop a chat application, what are the best practices to work with Apple notifications? – CeccoCQ Sep 28 '15 at 17:07
  • 1
    @CeccoCQ, WhatsApp could be using VoIP push notifications, since they have VoIP functionality. VoIP push notifications always relaunch the app, so maybe they have implemented some kind of "push-to-sync" with synchronisation. Also see my updated answer. – Baris Akar Sep 29 '15 at 06:19
  • Thats right there is a special treatment by the iOS for push notifications when the app includes VoIP in it. – hasan Sep 29 '15 at 06:43
  • I suspected that they use the PushKit framework. But Telegram? Telegram doesn't not provide VoIp Push Notifications. Can I use PushKit in an app that doesn't provide the Voip feature? – CeccoCQ Sep 29 '15 at 13:40
  • I doubt your app would go through the review process, if you use PushKit without providing VoIP capability... – Baris Akar Sep 29 '15 at 14:06