>我有对象数组,其中包括要发送的玩家ID和用户信息。是否可以使用 rest api 调用逐个发送推送通知。是否可以循环所有设备 ID 来完成。如何使用 REST API 调用实现此目的。提前谢谢。
我有这样的信息
[
{
"deviceid": 12345678534549,
"userinfo": "Hello venkatesh"
},
{
"deviceid": 123456435910010,
"userinfo": "Hello Pradeep"
},
{
"deviceid": 123445535356789,
"userinfo": "Hello Chaitanya"
}
]
for(var i =0; i< pushinfo.length; i++){
var message = {
app_id: "myappid",
contents: { "en": pushinfo[i].userinfo },
include_player_ids: [pushinfo[i].deviceid],
data: { "notification": 'rpi_alarm' }
};
sendNotification(message);
不要用于本机,您可以在推送通知时使用异步 eachSeries。
var async = require('async'(
var data =
[
{
"deviceid": 12345678534549,
"userinfo": "Hello venkatesh"
},
{
"deviceid": 123456435910010,
"userinfo": "Hello Pradeep"
},
{
"deviceid": 123445535356789,
"userinfo": "Hello Chaitanya"
}
]
async.eachSeries(data,function(item,cb){
playerIds.push(item.deviceid)
var message = {
app_id: "myappid",
contents: { "en": item.userinfo },
include_player_ids: item.deviceid,
data: { "notification": 'rpi_alarm' }
};
cb()
})