删除网络推送通知 [英] Remove a Web Push Notification

查看:73
本文介绍了删除网络推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在显示后删除网络推送通知?要将其从设备上的通知列表中删除 - 或将其标记为已读"?

Is there a way to remove a Web Push Notification once shown? To remove it from the notification list on the device - or mark it as "read"?

我认为这不能从服务器完成,我一直在寻找 Javascript API - 但我没有找到任何东西.

I assume this can't be done from the server, and I've been hunting around for a Javascript API - but I haven't found anything.

(我试图解决的更广泛的问题是如何在多个屏幕/浏览器/设备上同步通知.)

(The wider problem that I'm trying to crack is how to synchronise notifications on multiple screens/browsers/devices.)

推荐答案

我发现的关闭解决方案是在显示后关闭通知.以下是我拥有的代码解决方案.

The closes solution that I found was closing the notification after it was shown. Below is the code solution that I have.

event.waitUntil(
    self.registration.showNotification(title, options)
    .then(function (data) {
        self.registration.getNotifications()
        .then(function (notifications) {
            setTimeout(function () {
                //console.log(notifications);
                notifications.forEach(notification => notification.close())
            }, 10);
        })
    })
);

这篇关于删除网络推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆