Как включить Firebase Cloud Messaging в проекте, созданном PWABuilder? - PullRequest
0 голосов
/ 13 апреля 2019

Я разрабатываю новый PWA и успешно включил push-уведомления с помощью Firebase SDK. Теперь я попытался сгенерировать оболочки, используя https://www.pwabuilder.com/, но не могу заставить работать FCM. Я включил все необходимые разрешения, но, похоже, мне не удалось получить маркер firebase.

Это для PWA, разработанного с использованием https://github.com/react-boilerplate/react-boilerplate

Это мой 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);
});
...