在Firefox中,服务工作者的默认空闲时间为30秒。因此,在停止后,我们使用FCM api与邮递员发送了推送通知,它正在重新启动服务工作程序,但是前台和后台消息都没有收到推送通知。
我们正在使用json
文件中的动态配置来初始化Firebase应用。 (例如:-dev,uat,production),我们正在使用FCM
在我们的Web应用程序中使用angularJs(version-1.4.8)
。我已经添加了
firebase-messaging-sw.js
服务人员的代码段。
如果我在firebase-messaging-sw.js
中使用静态配置而不是动态配置来初始化Firebase应用程序,则它将开始正常运行。
// Import and configure the Firebase SDK
// These scripts are made available when the app is served or deployed on Firebase Hosting
// If you do not serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup
importScripts('https://www.gstatic.com/firebasejs/7.18.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.18.0/firebase-messaging.js');
var url = "dist/env/config.json";
fetch(url)
.then(
function (response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function (data) {
var fcmConfig = data.fcmConfiguration;
firebase.initializeApp({
apiKey: fcmConfig.apiKey,
projectId: fcmConfig.projectId,
messagingSenderId: fcmConfig.messagingSenderId,
appId: fcmConfig.appId
});
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: '/images/glyphicons_003_user.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
});
}
)
.catch(function (err) {
console.log('Fetch Error :-S', err);
});