我尝试使用Firebase 6和Firebase文档提供的Java脚本sdk在Web上实现Web上的推送通知,但出现类似“ Uncaught TypeError:firebase.messaging不是函数”之类的错误。我只是使用firebase提供的JS代码段。下面是代码
引用链接为https://firebase.google.com/docs/cloud-messaging/js/client?authuser=0
<!DOCTYPE html>
<html>
<head>
<title>Web Push Notification in PHP/MySQL using FCM</title>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.0.4/firebase-app.js"></script>
<link rel="manifest" href="manifest.json">
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyAzuh1fesmEJKgN3fF7DIehYR8bOOq9ANcbUg",
authDomain: "event-15587585460364484.firebaseapp.com",
databaseURL: "https://event-15587585460364484.firebaseio.com",
projectId: "events-1558460364484",
storageBucket: "event-15587585460364484.appspot.com",
messagingSenderId: "70279074255",
appId: "1:70279074255:web:785fb8938884a2078"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Retrieve Firebase Messaging object.
const messaging = firebase.messaging();
</script>
</head>
<body>
</body>
manifest.json
{
"gcm_sender_id": "103953800507"
}