如何在PWABuilder生成的项目上启用Firebase Cloud Messaging?

时间:2019-04-13 20:51:48

标签: firebase-cloud-messaging progressive-web-apps pwabuilder

我正在开发新的PWA,并且使用Firebase SDK成功启用了推送通知。现在,我尝试使用https://www.pwabuilder.com/生成包装器,但无法使FCM正常工作。我已经启用了所有必需的权限,但似乎无法获取firebase令牌。

这是使用https://github.com/react-boilerplate/react-boilerplate

开发的PWA

这是我的sw.js

/* eslint-disable */
// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/5.5.7/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.5.7/firebase-messaging.js');

// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({
    apiKey,
    authDomain,
    databaseURL,
    projectId,
    storageBucket,
    messagingSenderId
});

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(payload => {
    const title = payload.notification.title;
    const options = {
      body: payload.notification.body,
      icon: payload.notification.icon
    }
    return self.registration.showNotification(title, options);
});

0 个答案:

没有答案