Firebase Web推送通知停止在后台触发

时间:2019-11-27 09:28:42

标签: firebase web background service-worker

我有一种情况,由于某种原因,推送通知不会在后台触发。这间歇性地发生,并在稍后开始工作!我可以在Chrome的“推送消息”控制台上看到收到的通知。有人遇到过这个问题吗?

这是我对服务人员的通知句柄


importScripts('https://www.gstatic.com/firebasejs/6.3.4/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/6.3.4/firebase-messaging.js');

var firebaseConfig = {
    ...
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

const messaging = firebase.messaging();


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: '/Assets/Mystays/images/mystays-logo.png',
        image: '/Assets/Mystays/images/mystays-logo512.png',
        badge: '/Assets/Mystays/images/mystays-logo256.png'
    };


    return self.registration.showNotification(notificationTitle,notificationOptions);
}); 

感谢任何帮助

0 个答案:

没有答案