Javascript firebase.messaging不是一个函数
我正在使用Firebase的FriendlyChat codelab的代码在我的web应用程序中实现聊天功能。我想发送推送通知,Firebase解释说这是可能的。然而,我不断听到“firebase.messaging不是一个功能”,我完全不明白它的意思 有人碰到过这个吗?有人找到解决办法了吗 在my html中初始化firebase的脚本:Javascript firebase.messaging不是一个函数,javascript,firebase,google-cloud-messaging,firebase-cloud-messaging,Javascript,Firebase,Google Cloud Messaging,Firebase Cloud Messaging,我正在使用Firebase的FriendlyChat codelab的代码在我的web应用程序中实现聊天功能。我想发送推送通知,Firebase解释说这是可能的。然而,我不断听到“firebase.messaging不是一个功能”,我完全不明白它的意思 有人碰到过这个吗?有人找到解决办法了吗 在my html中初始化firebase的脚本: var config = { apiKey:\\, authDomain: \\, databaseURL: \\, s
var config = {
apiKey:\\,
authDomain: \\,
databaseURL: \\,
storageBucket: \\,
messagingSenderId: \\
};
firebase.initializeApp(config);
this.auth = firebase.auth();
this.database = firebase.database();
this.storage = firebase.storage();
this.messaging = firebase.messaging();
Messenger.js:
// Saves the messaging device token to the datastore.
FriendlyChat.prototype.saveMessagingDeviceToken = function() {
firebase.messaging().getToken().then(function(currentToken) {
if (currentToken) {
console.log('Got FCM device token:', currentToken);
// Saving the Device Token to the datastore.
firebase.database().ref('/fcmTokens').child(currentToken)
.set(firebase.auth().currentUser.uid);
} else {
// Need to request permissions to show notifications.
this.requestNotificationsPermissions();
}
}.bind(this)).catch(function(error){
console.error('Unable to get messaging token.', error);
});
};
// Requests permissions to show notifications.
FriendlyChat.prototype.requestNotificationsPermissions = function() {
console.log('Requesting notifications permission...');
firebase.messaging().requestPermission().then(function() {
// Notification permission granted.
this.saveMessagingDeviceToken();
}.bind(this)).catch(function(error) {
console.error('Unable to get permission to notify.', error);
});
};
您似乎没有包括Firebase消息传递SDK:
请注意,这个问题源于一个要求学生运行Firebase 3.8的教程,这可能会让人困惑。以下是本教程中步骤的链接: