【问题标题】:Send payload notification with node-gcm to android device使用 node-gcm 向 Android 设备发送有效负载通知
【发布时间】:2014-02-12 02:29:51
【问题描述】:

我正在使用 node-gcm 通过 GG GCM 向 android 设备发送通知。问题是,当我发送 2 条或更多消息时,它们相互重叠(旧消息消失,新消息替换它)。当我断开我的设备与互联网的连接,然后发送 2 条消息时,我连接到互联网并且只有一个通知与我发送的最后一条消息。这是发送消息的代码,正如GG在他们的指南中所说,我已经删除了collapse_key:

function sendNoti(content){

// with object values
var message = new gcm.Message({
    //collapseKey: 'cms',
    //delayWhileIdle: true,
    //timeToLive: 10,
    data: {
        news: content
    }
});
var sender = new gcm.Sender('MY KEY');
var registrationIds = [];
db.noti.find({}, function (err, getted) {
    getted.forEach(function (each) {
        registrationIds.push(each.regId);
    });

    /**
     * Params: message-literal, registrationIds-array, No. of retries, callback-function
     **/
    sender.send(message, registrationIds, 10, function (err, result) {
        console.log(result);
    });
})
}

请帮我解决这个问题。非常感谢!

【问题讨论】:

    标签: android node.js push-notification google-cloud-messaging


    【解决方案1】:

    您的服务器代码与您的问题无关。 您的客户端代码可能正在显示带有常量标识符的通知。这会导致每个新通知都会覆盖之前的通知。

    您必须更改通知方法调用:

    notificationManager.notify (CONSTANT_NOTIFICATION_ID, notification);
    

    到:

    notificationManager.notify (unique_identifier, notification);
    

    【讨论】:

      猜你喜欢
      • 2014-11-09
      • 2017-01-08
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      • 1970-01-01
      相关资源
      最近更新 更多