获取信息设备注册用户GCM

时间:2013-04-08 07:41:50

标签: javascript android cordova

我正在使用Node.js通过registrationIds从设备客户端手动将信息推送到设备。但我不知道如何直接从服务器registrationIds GCM获取信息,而不必在我想向客户端发送消息时手动输入。

例:我要替换的 APA91bHg7QEO3h44OCrBAb6yoHEvNvVSrRRcJjufS5fduCw2YhC83BZ9eqlxYS9PbKIAoFrmK-rvNEQ-CxrAjy4Wy13CRt5or1h7kG9XDRg2Tcy4zx8EpGOYLybmgnLDmVVvTJF4PR9Y 使用的ID直接取自GCM

代码服务器:

var gcm = require('node-gcm');
//var gcm = require('../gcm.js');

var message = new gcm.Message();
var sender = new gcm.Sender('AIzaSyB8IAgyo9DJbmGiVISnCCoxcQRD7em6KfI');
var registrationIds = [];

message.addData('title','Long Van');
message.addData('message','Ket qua xo so moi nhat!!!!');
message.addData('msgcnt','1');
message.collapseKey = 'demo';
message.delayWhileIdle = true;
message.timeToLive = 3;

// At least one token is required - each app registers a different token
 registrationIds.push('APA91bHg7QEO3h44OCrBAb6yoHEvNvVSrRRcJjufS5fduCw2YhC83BZ9eqlxYS9PbKIAoFrmK-rvNEQ-CxrAjy4Wy13CRt5or1h7kG9XDRg2Tcy4zx8EpGOYLybmgnLDmVVvTJF4PR9Y');

/**
 * Parameters: message-literal, registrationIds-array, No. of retries, callback-function
 */

sender.send(message, registrationIds, 4, function (result) {
console.log(result);
});
/** Use the following line if you want to send the message without retries
sender.sendNoRetry(message, registrationIds, function (result) {
console.log(result); });
**/

1 个答案:

答案 0 :(得分:0)

正确的方法是当设备向GCM注册时,GCM将返回令牌ID /注册ID(无论你怎么称呼它),此时,你应该用这个ID更新你的服务器以及一些额外的信息来识别ID(可能是关联的电子邮件或用户名?)