FCM:无法点击通知 [英] FCM: Cannot click notification

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

问题描述

我使用的是最近发布的 FCM消息支持推送铬上的通知。当我的应用程序在后台,我得到的通知,但没有任何反应,当我点击通知。如何指定当用户点击通知时应该打开的URL? (我明白如何使用notificationclick事件使用纯服务工作者的概念,我想知道如何使用

  messaging.setBackgroundMessageHandler(function(payload){
var data = payload || {};
var shinyData = decoder.run(data);
$ b console.log('[firebase-messaging-sw.js])收到后台消息',shinyData);

return self.registration.showNotification(shinyData.title,{
body:shinyData.body,
icon:shinyData.icon
})
});

我在这里错过了什么?

解决方案

click_action 不是 showNotification 函数。

要处理点击通知,一个 notificationclick 事件处理程序。



例如:

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


I'm using the recently release FCM messaging support for push notifications on the chrome. When my app is in the background, I get the notification but nothing happens when I click the notification. How to I specify the URL which should open when the user clicks the notification? (I understand how its done using the pure service worker concept using the notificationclick event, I want to know how to do that using FCM messaging.)

messaging.setBackgroundMessageHandler(function(payload) {
  var data = payload || {};
  var shinyData = decoder.run(data);

  console.log('[firebase-messaging-sw.js] Received background message ', shinyData);

  return self.registration.showNotification(shinyData.title, {
    body: shinyData.body,
    icon: shinyData.icon
  })
});

What am I missing here?

解决方案

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));
});

这篇关于FCM:无法点击通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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