我必须在一分钟后隐藏推送通知。为了实现这一目标,我应该在 Service Worker 中做什么?
您可以使用notification.close() 方法 https://developer.mozilla.org/en-US/docs/Web/API/Notification/close。您可以获得通知 https://developer.mozilla.org/en-US/docs/Web/API/Notification对象与ServiceWorkerRegistration.getNotifications https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/getNotifications.
例如:
self.addEventListener('push', event => {
event.waitUntil(
self.registration.showNotification('Title', {
body: 'Body.',
})
.then(() => self.registration.getNotifications())
.then(notifications => {
setTimeout(() => notifications.forEach(notification => notification.close()), 60000);
})
);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)