简体   繁体   English

如何将未读消息的 iOS 推送通知分组为一个

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

We have a messenger on iOS client.我们在 iOS 客户端上有一个 Messenger。

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.据我所知,APN 的配置是从服务器完成的。 Or it should be done from the client?还是应该从客户端完成?

I read about apns-collapse-id , will it help me?我读到了apns-collapse-id ,它对我有帮助吗? 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.在 iOS 中,Apple 推送通知服务包括一个执行存储转发功能的服务质量组件。 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.如果 APNs 尝试传递通知并且目标设备处于离线状态,APNs 会将通知存储一段有限的时间,并在设备再次可用时传递它。 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.现在,如果您的设备在线并且我们在默认情况下收到设备 iOS 的多个通知,则按应用对通知进行分组,因此,如果您只需要在应用级别对所有通知进行分组,则无需执行任何操作,因为它是由操作系统本身。 However, if you need to to group notification based on some topic iOS also has good support for custom grouping.但是,如果您需要根据某些主题对通知进行分组,iOS 也对自定义分组有很好的支持。 For more info on custom grouping, you can refer to : https://developer.apple.com/videos/play/wwdc2018/711/有关自定义分组的更多信息,您可以参考: https : //developer.apple.com/videos/play/wwdc2018/711/

I read about apns-collapse-id, will it help me?我读到了 apns-collapse-id,这对我有帮助吗? Will it display the total amount of unread messages它会显示未读消息的总数吗

apns-collapse-id is used to create notifications which should be replaced with newer ones. apns-collapse-id用于创建应替换为新通知的通知。 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.因此,如果设备在线并收到多个具有相同apns-collapse-id 的推送通知,那么它会丢弃之前的通知并在通知中心显示新的通知。 So there will always be only one notification in the notification center with a given apns-collapse-id .因此,通知中心中始终只有一个具有给定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.因此,在您的情况下,您可以通过在请求标头中设置apns-collapse-id并始终在通知正文中发送更新的未读消息计数来利用这一点,因此在这种情况下,通知中始终只有一个通知中心将被服务器一次又一次地替换为新发送的计数。 Make sure to set same apns-collapse-id for all the notification.确保为所有通知设置相同的apns-collapse-id 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/有关apns-collapse-id 的更多信息,您可以参考: https : //developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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