'Group notifications with Expo
I have a react native messaging app done with Expo. I got notifications to work, but the problem is that each message is a separate notification.
I would like to group notifications sent by the same person. Currently, I have:
[Notification]
John - Hey, how are you?
[Notification]
John - Long time no see!
and I would like them to merge as a single one when the second message is received, like this:
[Notification]
John |
Hey, how are you?
Long time to see!
I might be missing something because I cannot find anyone else wondering about such a common functionality.
The code I use to send notifications from my backend (python):
headers = {
'Accept': 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
}
session.post(
"https://exp.host/--/api/v2/push/send",
json = {
"to": expo_token,
"title": username,
"body": message_content,
},
headers=headers
)
Solution 1:[1]
In iOS you should use apns-collapse-id
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
An identifier you use to coalesce multiple notifications into a single notification for the user. Typically, each notification request causes a new notification to be displayed on the user’s device. When sending the same notification more than once, use the same value in this header to coalesce the requests. The value of this key must not exceed 64 bytes.
Update
For using collapse feature, you can use for Notifications other service. Which supports collapse and react native - for example
https://documentation.onesignal.com/docs/how-notifications-work#section-notification-collapsing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |