实时数据库中的数据更改未收到fcm

问题描述 投票:0回答:1

我写了一个云函数来接收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。

android firebase firebase-realtime-database firebase-cloud-messaging google-cloud-functions
1个回答
0
投票

我使用/news-6ff9e作为我的参考,这是项目ID。我用我的数据库对象改变了这个并解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.