我正在寻找一种将推送消息从我的 Express JS 服务器传递到我的离子应用程序的方法,我发现GCM。使用 GCM,我可以传递传递令牌列表的消息,如下所示:
sender.send(message, {
registrationTokens: deviceTokens
}, function (err, response) {
if (err) console.error(err);
else console.log('response' + JSON.stringify(response));
});
但当我发现GCM became FCM我尝试使用 FCM 做同样的事情,但直到现在还没有成功。我听说过发送主题,但找不到示例。
谁能举例说明如何使用 FCM 发送主题消息?
我的 FCM 代码:(仅使用 1 个令牌)
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 https://www.npmjs.com/package/fcm-push用于推送通知的库,
如果您想向多个用户发送相同的通知,请使用“registration_ids”参数而不是“to”。该标签接受字符串数组。
前任:
Registration_ids:["registrationkey1","registrationkey2"]。
注意:一次限制为 100 个密钥。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)