问题描述
我有以下问题:我实现了一个服务工作者,我想通过该工作者发送通知(这部分工作正常)。我为这个服务人员创建了事件监听器。但是,安装事件或onnotificationclick事件的事件侦听器起作用。但是,主动关闭通知时,永远不会触发onnotificationclose事件。 有人可以帮助我,告诉我我的错误在哪里吗? 在下面,您可以找到我的代码的相关部分:
在我的服务工作者文件中
self.onnotificationclick = function(event) {
console.log('On notification click: ',event.notification.tag);
}
self.onnotificationclose = function(event) {
console.log('On notification close Service worker: ',event.notification.tag);
}
在我的用于发送通知的js文件中
const notificationTitle = 'Message Title';
const notificationOptions = {
body: ' Message body.',tag: 'notification',data: {
"identifier": "identifier",}
};
navigator.serviceWorker.getRegistration().then(function (reg) {
reg.showNotification(notificationTitle,notificationOptions);
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)