如何使用 node-fcm 向多个设备发送通知
how to send notification to multiple devices using node-fcm
应用关闭时通知不起作用
const 令牌 = ["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")
}
});
})
问题是如何在其中设置通知标题?并且通知不起作用应用程序既不在后台也不在前台关闭为什么?
试试这个方法..
如果标记在数组中并将信息传递到数据对象,请使用“registration_ids”而不是“to”。
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");
}
});
});
应用关闭时通知不起作用
const 令牌 = ["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")
}
});
})
问题是如何在其中设置通知标题?并且通知不起作用应用程序既不在后台也不在前台关闭为什么?
试试这个方法..
如果标记在数组中并将信息传递到数据对象,请使用“registration_ids”而不是“to”。
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");
}
});
});