2013-04-08 108 views
0

我正在使用Node.js手動將信息推送到設備,通過registrationIds從設備客戶端中刪除。但我不知道如何直接從服務器registrationIds GCM獲取信息,而無需在需要向客戶端發送消息時手動輸入信息。獲取信息設備註冊用戶GCM

例如:我想具有id直接從GCM採取更換APA91bHg7QEO3h44OCrBAb6yoHEvNvVSrRRcJjufS5fduCw2YhC83BZ9eqlxYS9PbKIAoFrmK-rvNEQ-CxrAjy4Wy13CRt5or1h7kG9XDRg2Tcy4zx8EpGOYLybmgnLDmVVvTJF4PR9Y

代碼服務器:

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); }); 
**/ 

回答

0

正確的方法是,當與GCM設備寄存器,GCM將返回令牌ID /註冊ID(無論你怎麼稱呼它),在這個時候,你應該更新帶有此ID的服務器以及一些其他信息以識別該ID(可能是相關的電子郵件或用戶名?)