逐个发送一个信号推送通知

时间:2018-03-12 15:53:30

标签: node.js push-notification ionic2 onesignal

我有一个对象数组,包括要发送的playerid和userinfo。是否可以通过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);

1 个答案:

答案 0 :(得分:1)

不要用于本机,在推送通知时可以使用异步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()
})