GCM推送通知NodeJS

时间:2016-04-13 09:29:14

标签: node.js express

我是新手推送通知,我已经完成了我从谷歌搜索引用的代码部分,它工作正常,但我的查询是:

  1. 向一群人发送推送通知(使用数组)
  2. 并且该阵列中至少有一个错误的gcm-id
  3. 如果gcm-id错误,请填写“未注册”或“MisplacingId”等错误(单独发送时)
  4. 现在,gcm-id在一个数组中,那么推送会发送给剩下的人还是会阻止它自己?
  5. 这是我的代码:

    var GCM = require('gcm').GCM;
    var apiKey = 'xyz';
    var gcm = new GCM('apiKey');
    
    var message = {
        registration_id: ['x','y'],
        collapse_key: 'Hello',
        priority: 'high', 
        contentAvailable: true,
        delayWhileIdle: true,
        timeToLive: 3,
    };
    
    gcm.send(message, function(err, messageId){
        if (err) {
            console.log("Something has gone wrong!");
            console.log(err);
        } else {
            console.log("Sent with message ID: ", messageId);
        }
    });
    

    请告诉我有任何限制(gcmid的数量)?一推?

1 个答案:

答案 0 :(得分:0)

它会向所有注册ID发送推送通知,即使它们中的少数似乎在阵列之间无效也是如此。 注册ID无效时的示例响应

{
  multicast_id: 8976424350191695000,
  success: 1,
  failure: 1,
  canonical_ids: 1,
  results: [
    {
      registration_id: "value-of-correct-registration-id",
      message_id: "0:1460568231005603%ade1213ff9fd7ecd"
    },
    {
      error: "InvalidRegistration"
    }
  ]
}

成功和失败计数将显示已发送和失败的推送通知的数量。并且注册ID的数量没有限制。