0

我在 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));
4

1 回答 1

0

听起来您没有发送配置为“可折叠”的消息。默认情况下,每条消息都是不同的,不会覆盖最后一条消息。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();
    }
于 2019-02-19T13:33:11.627 回答