我已经编写了一个云函数来接收fcm,只要数据库发生了变化,但目前它无法正常工作:
exports.sendPush = functions.database.ref('/news-6ff9e').onWrite(event => {
let projectStateChanged = false;
let projectCreated = false;
let projectData = event.data.val();
if (!event.data.previous.exists()) {
projectCreated = true;
}
if (!projectCreated && event.data.changed()) {
projectStateChanged = true;
}
let msg = 'A project state was changed';
if (projectCreated) {
msg = `The following new project was added to the project: ${projectData.title}`;
}
let payload = {
notification: {
title: 'Firebase Notification',
body: msg,
sound: 'default',
badge: '1'
}
};
return admin.messaging().sendToTopic("/topics/news", payload);
});
/news-6ff9e
是我的项目ID。
答案 0 :(得分:0)
我使用/news-6ff9e
作为项目ID的参考。我已经使用我的数据库对象更改了此问题并解决了问题。