如何使用Firebase Cloud Messaging将推送通知发送到多个设备 [英] How to send push notifications to multiple devices using Firebase Cloud Messaging
问题描述
我找到了一种方法,可以将express消息从我的expressJS服务器发送到我的离子应用程序,我发现 GCM 。使用GCM,我可以传递通过一系列令牌的消息,如下所示:
I was findind a way to deliver push messages from my expressJS server to my ionic app and I found GCM. With GCM I could deliver the message passing a list of tokens, like this :
sender.send(message, {
registrationTokens: deviceTokens
}, function (err, response) {
if (err) console.error(err);
else console.log('response' + JSON.stringify(response));
});
但是,当我发现 GCM 变为 FCM 我试图用FCM做同样的事,但到现在还没有运气。我听说过发送主题,但是找不到一个例子。
But as I found that GCM became FCM I was trying to do the same using FCM, but no luck until now. I've heard about sending topics but I couldn't find an example.
任何人都可以给出关于如何使用FCM发送主题消息的示例?
Can anyone give an example on how send topic messages using FCM ?
我的FCM代码:(仅使用1个令牌)
my FCM code: (working with just 1 token)
var FCM = require('fcm-node');
var serverKey = 'xxx';
var fcm = new FCM(serverKey);
var message = {
to: 'device-token',
notification: {
title: event.title,
body: event.information
}
};
fcm.send(message, function (err, response) {
if (err) {
console.log("Something has gone wrong! \n" + err);
} else {
console.log("Successfully sent with response: \n ", JSON.stringify(response));
}
});
推荐答案
我估计你使用 fcm push 您的推送通知库,
如果要向多个用户发送相同的通知,然后使用registration_ids参数,而不是to。这个标签接受一串字符串。
I reckon you are using fcm push library for your push notification, if you want to send same notification to multiple users then use "registration_ids" parameter instead of "to". this tag accepts an array of strings.
ex:
registration_ids:[registrationkey1,registrationkey2]。
ex: registration_ids:["registrationkey1","registrationkey2"].
注意:limit一次是100个键。
note: limit is 100 key at a time.
这篇关于如何使用Firebase Cloud Messaging将推送通知发送到多个设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!