我的FCM有问题。当我调用firebase.messaging()时,我遵循fcm的文档,但报错:Uncaught TypeError:firebase.messaging不是一个函数。
const消息= firebase.messaging(); messages.usePublicVapidKey('BGWGPG6yoYAa9zLB9Rhd_ov3w6o3cgpE3zk0KczWhEzbe_zHAAzThhtH3Gtl1XnIyZWdwmB4bocHIW9US1hiJ4k');
请帮帮我!预先感谢您的帮助
答案 0 :(得分:0)
请参阅:
import firebase from "firebase/app";
import "firebase/messaging";
const firebaseConfig = {
// Your config
}
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
let messaging = null;
try {
if (firebase.messaging.isSupported()) {
messaging = firebase.messaging();
messaging.usePublicVapidKey("Your Sender ID");
}
} catch (e) {}
importScripts("https://www.gstatic.com/firebasejs/6.1.0/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/6.1.0/firebase-messaging.js");
const messagingSenderId = "Your Sender ID";
firebase.initializeApp({ messagingSenderId });
try {
if (firebase.messaging.isSupported()) {
const messaging = firebase.messaging();
}
} catch (e) {}