简体   繁体   中英

How to group iOS push notifications for unread messages into a single one

We have a messenger on iOS client.

When you disable internet on the device, receive many messages and enable the internet, the device receives many push notifications. I want to receive only one push notification with the total count of unread messages.

How can I achieve this from the server side? As far as I know, configuration of APNs is done from the server. Or it should be done from the client?

I read about apns-collapse-id , will it help me? Will it display the total amount of unread messages?

In iOS, Apple Push Notification service includes a Quality of Service component that performs a store-and-forward function. If APNs attempts to deliver a notification and the destination device is offline, APNs stores the notification for a limited period of time and delivers it when the device becomes available again. This component stores only the most recent notification per device and per app. If a device is offline, sending a notification request targeting that device causes the previous request to be discarded. So incase the device is offline it will always receive the latest notification.

Now if your device is online and we receive multiple notifications to the device iOS by default group the notifications by app, So incase you only require all your notifications to be grouped on app level you don`t need to do anything as it is done by OS itself. However, if you need to to group notification based on some topic iOS also has good support for custom grouping. For more info on custom grouping, you can refer to : https://developer.apple.com/videos/play/wwdc2018/711/

I read about apns-collapse-id, will it help me? Will it display the total amount of unread messages

apns-collapse-id is used to create notifications which should be replaced with newer ones. So if the device is online and receives multiple push notifications with same apns-collapse-id , then it discard the previous notification and displays the new one in the notification center. So there will always be only one notification in the notification center with a given apns-collapse-id . So in your case you can make use of this, by setting the apns-collapse-id in the request header and always sending the updated unread message count in the notification body, so in that case there will always be only one notification in the notification center which will be replaced again and again with the newly sent count by the server. Make sure to set same apns-collapse-id for all the notification. For more info on apns-collapse-id you can refer : https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM