【发布时间】:2020-08-11 12:46:52
【问题描述】:
应用关闭时通知不起作用
const token = ["AAASDfsadfasdfaFDSDFSDLFJLSDAJF;DSJFAsdfdsfsdf"];
app.get('/send-notfication', (req, res) => {
var FCM = require('fcm-node');
var fcm = new FCM(serverKey);
var messageToSend = "Hi there this is message";
var message = {
to: token,
data: {
ar_message: messageToSend,
},
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!", err);
} else {
console.log("Successfully sent with response: ", response.results);
res.send("Successfully sent")
}
});
})
问题是如何在其中设置通知标题?并且通知不起作用应用程序在后台和前台都没有关闭,为什么?
【问题讨论】:
-
我相信这里不需要循环,并且通知在后台不起作用
-
错误:默认 Firebase 应用已存在。这意味着您多次调用 initializeApp() 而不提供应用程序名称作为第二个参数。在大多数情况下,您只需要调用一次 initializeApp()。但是,如果您确实要初始化多个应用程序,请将第二个参数传递给 initializeApp() 以给每个应用程序一个唯一的名称。
标签: node.js express push-notification firebase-cloud-messaging