1
我試圖使用FCM(Firebase Cloud Messaging)進行Web推送通知。 當Web應用程序選項卡處於焦點時,我已成功收到消息。FCM服務人員setBackgroundMessageHandler
但是當我關閉標籤時,應該調用服務人員(在FCM示例中爲firebase-messaging-sw.js
)。但它根本不叫setBackgroundMessageHandler
。
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: 'firebase-logo.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
您是否設置了'messagingSenderId'?因爲除此之外,您的代碼看起來與我所擁有的相同 - 並且這很有效。 : -/ –
是否關閉了該選項卡?我認爲它適用於選項卡未關閉且不活動的情況 –