Joh*_*ana 3 javascript node.js express google-cloud-messaging firebase-cloud-messaging
我找到了一种从我的expressJS服务器向我的离子应用程序发送推送消息的方法,我找到了GCM.使用GCM,我可以通过令牌列表传递消息,如下所示:
sender.send(message, {
registrationTokens: deviceTokens
}, function (err, response) {
if (err) console.error(err);
else console.log('response' + JSON.stringify(response));
});
Run Code Online (Sandbox Code Playgroud)
但是当我发现GCM成为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));
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9976 次 |
最近记录: |