I want to add push notifications to an chat application I am working on.
Initially I thought that I should write business logic to detect that a message wasn't delivered and then attempt to send the notification for the unread message. If a user's online presence is detected, I can skip the push notification call.
However, after doing some research, I discovered this answer from a support engineer at PubNub.
The answer states that they don't really care whether the subscription is active, they just send GCM/APNS requests for all messages.
The publisher does not know or care whether subscribers are active (foreground) or inactive (background or not running at all - kill state) on the device. Publisher always publishes the message with a GCM (and possibly APNS) payload.
Active apps will receive both and will prevent the display of the push notification via the OS's push msg receiver listener.
Inactive apps will receive only the push notification and display that. When end user taps the push msg, it will open the app where you can get the missed message and display the full content in your app's UI.
If I understand correctly, this would display a notification if the app is in the background and trigger a method (didReceiveRemoteNotification
iOS, ??? Android) if the app is open. I could then choose to display a local
notification depending on my own logic.
Is this good design or do chat applications generally make more effort to detect if a message was delivered before falling back to push notifications?