FCM: Cannot click notification

别等时光非礼了梦想. 提交于 2019-12-03 12:23:12

click_action is not one of the possible parameters of the showNotification function.

To handle the click on the notification, define a notificationclick event handler.

For example:

self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  event.waitUntil(self.clients.openWindow(YOUR_URL_HERE));
});

Marco's answer is correct.

The Firebase Messaging Library is a wrapper on top of the Web Push API.

The notification: { click_action: 'https://...' } payload will show a notification and handle the click for you. To achieve the same with data payload you should implement the notificationclick event listener (Like Marco suggested).

self.addEventListener('notificationclick', function(event) {
  event.notification.close();

  ... Do your stuff here.
});

You can also do the same with the notificationclose event:

self.addEventListener('notificationclose', function(event) {
  ... Do your stuff here.
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!