Can you expire / remove a message remotely on FCM?

落爺英雄遲暮 提交于 2021-01-28 08:35:51

问题


I'm using FCM for my push messages. Its great, however I've a client that needs to be able to remove a push message once its sent - (in case of mistakes / typos etc).

I know you can get the message id from when the Topic is queued to send messages, just wondering if there is a way to then use that ID to expire those messages remotely. i.e. to delete the message.


回答1:


There is currently no way to delete/remove a message from the server side/console. The message_id is just an identifier that the message was sent successfully to the FCM server.

What is usually used for this scenario is the tag parameter (see my answer here) where an existing notification with the same tag gets replaced with the newer one.




回答2:


There are scenarios where you might want a replacing notification to notify the user rather than silently update. Chat applications are a good example. In this case you should set tag and renotify to true.

write this code on your sw.js

    const title = 'Notification 2 of 2';
    const options = {
      tag: 'renotify',
      renotify: true
    };
    registration.showNotification(title, options);

You can test demo on here by clicking in renotify button



来源:https://stackoverflow.com/questions/48921958/can-you-expire-remove-a-message-remotely-on-fcm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!