Handling push notifications elegantly.
Push notifications help keep your customers up to date on information, but when the number of notifications is huge, the receivers may discard all the notifications together. This makes your customers miss important updates. In terms of providing the latest information to the customer, notifications with old information become obsolete and are to be discarded.
A collapsible message is a message that may be replaced by a new message if it is yet to be seen or acted upon by the customer. Using the collapse key feature, you can overwrite the last update to the customer with a latest update.
The following are some possible use-cases where a collapsible message is useful:
- Increase your sales by updating your customers with up-to-date offer details.
- Provide latest updates on election results.
- Keep updating your customer with the latest information on the Weather updates.
- Update sports fans with the latest scores.
- Update the latest order status to your customers for a hassle-free delivery.
APNS supports identifying multiple notifications into one single notification using the collapse identifier. Notifications with the same collapse identifier will only display the latest, and the older ones are discarded. This can be achieved by sending settings as part of the payload.
Android does not support this feature, but app implementation can be customized to achieve this feature in Android.
This blog provides the details of how it can be achieved in both the platforms.
Implement collapsing notifications in an iOS app
IBM Cloud Push Notifications supports this with the payload key
apnsCollapseId. The following is a sample payload for sending a notification with the
This sample app displays the notifications on build status. Two notifications are sent to the iOS App about the status of a build with the same
Since the second notification also has the same
apnsCollapseId and the user has not yet acted upon the notification, the old notification is replaced by the new one, and the user is displayed with only the new notification in the notification center.
Implement collapsing notifications in an Android app
By default, Android does not support collapsing the notifications, but the same result can be achieved by custom implementation.
Update the androidmanifest.xml file with the following. This helps override the Intent service:
This MessageIntentServiceOne is called when a new notification arrives for the app:
MessageIntentServiceOne.onMessageReceived is triggered when a new notification arrives. This method reads the
collapseId from the payload, and based on the
collapseId, replaces the old notification so that only the latest notification is displayed to the customer.
The following is a sample payload for sending a notification with the
Below are how the notifications are replaced in the Android notification center:
collapseKey settings supported by IBM Cloud Push Notifications for Android are applied only for dozed notifications; normal notifications will not support this feature.