不显示后台通知

时间:2019-03-31 11:19:11

标签: javascript node.js firebase firebase-cloud-messaging

enter image description here我是Firebase云消息传递的新手,我正在尝试在nodeJS上设置通知系统。我遵循了服务人员及其所有内容上的文档,但是存在一个问题,即使通知到达客户端,浏览器也不会显示通知。

service worker code :
importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js");
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({
  messagingSenderId: "901639143723"
});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
  console.log(
    "[firebase-messaging-sw.js NOIS] Received background message ",
    payload
  );
  var notificationTitle = "Background Message Title";
  var notificationOptions = {
    body: "HI"
    icon: "/firebase-logo.png"
  };
  console.log(
    self.registration.showNotification(notificationTitle, notificationOptions)
  );
  return self.registration.showNotification(
    notificationTitle,
    notificationOptions
  );
});
[![enter image description here][1]][1]
// Customize notification here

0 个答案:

没有答案