我将尝试使用云函数向我的React应用程序发送FCM。云函数正在执行,但客户端未收到通知。
以下是云函数代码:
以下是云函数代码:
exports.sendPush = functions.database.ref('/settings2').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}`;
}
tokens.push("fIGxxxxGtDGxxxx DEVICE Token");
let payload = {
notification: {
title: 'Firebase Notification',
body: 'This Is Message',
sound: 'default',
badge: '1'
}
};
return admin.messaging().sendToDevice(tokens, payload);
});
这是云函数的日志:
我客户端代码如下:
messaging.onMessage(function(payload) {
console.log("Message received. ", payload);
// ...
});
没有任何错误,但控制台中没有任何内容。我需要对 service worker 文件做些什么吗?
非常感谢任何帮助。