【发布时间】:2022-01-01 07:24:24
【问题描述】:
Firebase 客户端错误 this.bgMessageHandler.next 不是函数。
所有步骤都按照:https://firebase.google.com/docs/cloud-messaging/js/receive
我已经使用以下设置设置了一个 firebase 应用: 一个创建反应应用程序,以及下面提到的 service worker 文件。 我的 serviceworker 文件的内容:
importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js');
const firebaseApp = firebase.initializeApp({
apiKey: "lsdafjlksdfjlaskdfjlkadfjaldkf",
authDomain: "abcd.firebaseapp.com",
projectId: "abcd",
storageBucket: "abcd.appspot.com",
messagingSenderId: "394504395830",
appId: "asdljfdkjflasdf"
});
const messaging = firebase.messaging(firebaseApp);
messaging.onBackgroundMessage(messaging, (payload) => {
console.log('sw [firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png'
};
self.registration.showNotification(notificationTitle,
notificationOptions);
});
我正在通过 Firebase 控制台的 Firebase 撰写通知 UI 从后端触发通知。
【问题讨论】:
标签: firebase push-notification firebase-cloud-messaging service-worker