gpt4 book ai didi

ios - iPhone 通知中的旧消息未删除尝试

转载 作者:行者123 更新时间:2023-11-29 06:00:16 29 4
gpt4 key购买 nike

我在 ionic 3 应用程序中使用推送插件,一切正常,但从我的服务器端,我们一次发送一条消息,并且我正在向 iPhone 接收消息,但旧消息应该被新消息覆盖,或者一旦我们收到新消息消息然后旧消息会自动清除..我找不到与此相关的任何内容,请任何人帮助我解决这个问题。

 const options: PushOptions = {
android: {},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};

const pushObject: PushObject = this.push.init(options);


pushObject.on('notification').subscribe((notification: any) =>
console.log('Received a notification', notification));

最佳答案

听起来您没有发送配置为“可折叠”的消息。默认情况下,每条消息都是不同的,不会覆盖最后一条消息。 FCM 很好地记录了这一点:

https://firebase.google.com/docs/cloud-messaging/concept-options

Non-collapsible and collapsible messages

A non-collapsible message denotes that each individual message is delivered to the device. A non-collapsible message delivers some useful content, as opposed to a collapsible message like a content-free "ping" to the mobile app to contact the server to fetch data.

...

A collapsible message is a message that may be replaced by a new message if it has yet to be delivered to the device.

...

enter image description here

或者,如果您不使用 FCM,here's a reference直接访问 Apple 的 APN 文档。

To allow the coalescing of similar notifications, you can include a collapse identifier within a notification request. Normally, when a device is online, each notification request that you send to APNs results in a notification delivered to the device. However, when the apns-collapse-id key is present in your HTTP/2 request header, APNs coalesces requests whose value for that key is the same. For example, a news service that sends the same headline twice could use the same collapse identifier value for both requests. APNs would then coalesce the two requests into a single notification for delivery to the device. For details on the apns-collapse-id key

更新一些代码详细信息:

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();
}

关于ios - iPhone 通知中的旧消息未删除尝试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54749624/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com