1 回答

TA貢獻1757條經(jīng)驗 獲得超7個贊
您使用的是 Cloud Functions for Firebase 測試版中的語法。由于它已更新到 1.0,因此語法發(fā)生了變化,您需要更新代碼以匹配升級文檔中所述。
將其應用于您的代碼會導致如下結果:
var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.database.ref("/Users").onWrite((change, context) => {
var payload = {
notification: {
title: "A new user has been added!",
body: "Click to see"
}
};
if (change.before.exists()) {
if (change.before.numChildren() < change.after.numChildren()) {
return admin.messaging().sendToTopic("latest_events", payload);
} else {
return;
}
}
if (!change.after.exists()) {
return;
}
return admin.messaging().sendToTopic("latest_events", payload);
});
變化是:
有兩個參數(shù)傳遞到函數(shù)中,而以前只有一個。
您不再需要將配置傳遞到initializeApp.
在before和after快照現(xiàn)在可從change。
添加回答
舉報