我收到了 firebase 通知,我想在后台将它们显示为弹出式通知(当用户在不同的选项卡上时)。
在我的 firebase-messaging-sw.js
中,我尝试了两种不同的方法,它们都是 console.log()
有效负载,没关系,但后台没有弹出通知。
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[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'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
和
messaging.onBackgroundMessage((payload) => {
console.log('[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,但没有成功。那么,如何显示弹出窗口?