应用程序关闭时通知不起作用
const令牌=["AAASDfsadfasdfaFDSDFSDLFJLSDJF;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")
}
});
})
问题是如何在其中设置通知标题?通知不起作用,应用程序在后台和前台都关闭了,为什么?
试试这种方法。。
使用";registration_ids";而不是";至";if标记在数组中,并将信息传递到数据对象中。
app.get("/send-fcm-notification", (req, res) => {
var FCM = require("fcm-node");
var fcm = new FCM(serverKey);
var message = {
registration_ids: token,
data: {
title: "Hi there this is title",
message: "Hi there this is message"
},
};
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");
}
});
});