Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

javascript - PMA服务工作人员通知点击不起作用(PMA Service worker notification click isn't working)

I am trying to show a notification and do something when it is clicked.

(我试图显示一个通知,并在单击它时做一些事情。)

The part that shows is working well, is receiving data from the server, however, the function of clicking on the notification does not work, I have done everything the documentation says, what I found on the web and here, everything points with the same functionality that I have implemented but it doesn't seem to work.

(显示的部分工作正常,正在从服务器接收数据,但是,单击通知的功能不起作用,我已经完成了文档说的所有内容,在网络上发现的内容以及此处指向的所有内容我已实现的功能,但似乎无法正常工作。)

I have made fictitious practices and as long as the data is not loaded from the server, the click is triggered, otherwise, with the data it does not.

(我已经进行了虚拟操作,只要不从服务器加载数据,就会触发单击,否则,数据就不会触发。)

Can anyone tell me what I am doing wrong?

(谁能告诉我我在做什么错?)

I'll really apreciate some help, I've two days with these.

(我会非常感谢您的帮助,我已经做了两天。)

self.addEventListener('push', (e) => {
  let notification = e.data.json();
  const title = 'My app ' + notification.title;
  const options = {
      body: notification.msg,
      actions: [
        { action: 'yes', title: 'Aprobar' },
        { action: 'no', title: 'Rechazar' }
      ]
  };
  self.registration.showNotification(title, options);
}); //to show the notification with server info

self.addEventListener('notificationclick', function (event) {
   console.log(event);
   var noti = event.notification.data;
   let r = event.notification.data.json();
   console.log(noti); }, 
false); //handling the click

I've also tried with notificationclose to see if it catchs the click but it does not work either.

(我也尝试过使用notificationclose来查看它是否捕获了点击,但它也不起作用。)

Important to note that it does not display any error or warning, it does simple do anything.

(重要的是要注意,它不显示任何错误或警告,它可以简单地执行任何操作。)

  ask by Danielle Lpz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...