【发布时间】:2021-11-09 17:33:40
【问题描述】:
我正在按照docs 中提到的代码通过 Admin SDK 发送通知。
exports.sendNotification = functions.https.onRequest((req, res) => {
const message = {
data: {
type: "warning",
content: "A new weather warning has been created!",
},
topic: "weather",
};
admin
.messaging()
.send(message)
.then((response) => {
console.log("Successfully sent message:", response);
})
.catch((error) => {
console.log("Error sending message:", error);
});
res.end();
});
使用 Firebase 模拟器运行上述代码后,控制台打印
i functions: Beginning execution of "us-central1-sendNotification"
i functions: Finished "us-central1-sendNotification" in ~1s
> Successfully sent message: projects/foo/messages/2216986345254434321
但是,我在设备上看不到任何通知。
注意:如果我通过 Firebase Notification composer 或 Postman 将通知发送到同一主题 weather,则设备会显示通知。不知道上面的代码有什么问题。
【问题讨论】:
标签: android node.js flutter firebase-cloud-messaging google-cloud-messaging