听起来您没有发送配置为“可折叠”的消息。默认情况下,每条消息都是不同的,不会覆盖最后一条消息。FCM 很好地记录了这一点:
https://firebase.google.com/docs/cloud-messaging/concept-options
不可折叠和可折叠的消息
不可折叠的消息表示每个单独的消息都被传递到设备。不可折叠的消息会传递一些有用的内容,而不是像无内容的“ping”这样的可折叠消息,它会发送到移动应用程序以联系服务器以获取数据。
...
可折叠消息是可以被新消息替换的消息,如果它还没有被传递到设备。
...

或者,如果您不使用 FCM,请直接参考Apple 的 APN 文档。
要允许合并类似的通知,您可以在通知请求中包含折叠标识符。通常,当设备在线时,您向 APNs 发送的每个通知请求都会导致向设备发送通知。但是,当您的 HTTP/2 请求标头中存在 apns-collapse-id 键时,APNs 会合并该键值相同的请求。例如,两次发送相同标题的新闻服务可以对两个请求使用相同的折叠标识符值。然后,APN 会将这两个请求合并为一个通知,以便传送到设备。有关 apns-collapse-id 键的详细信息
更新一些代码细节:
public void sendMessage(String title, String body, Map<String, String> data, boolean shouldCollapse) {
PlatformConfiguration platformConfig = new PlatformConfiguration(30);
if (shouldCollapse)
messageBuilder.setAndroidConfig(platformConfig.getCollapsibleAndroidConfig("test")).setApnsConfig(platformConfig.getCollapsibleApnsConfig("test"));
...
public ApnsConfig getCollapsibleApnsConfig(String collapseKey) {
return getCoreApnsConfig().putHeader("apns-collapse-id", collapseKey)
.setAps(getNonCollapsibleApsBuilder().setCategory(collapseKey).setThreadId(collapseKey).build()).build();
}
public AndroidConfig getCollapsibleAndroidConfig(String collapseKey) {
return getCoreAndroidConfig().setCollapseKey(collapseKey)
.setNotification(
getNonCollapsibleAndroidNotificationBuilder().setTag(collapseKey).build()).build();
}