There is a client application that receives push notifications through the GCM.
It works like this: 1. the application is registered in GCM and gets registration_id (token) 2. I am sending this token to the application server 3. Further sending a push-notification from application server I set this token and corresponding device receives a message .
I am interested in how to be when: - the user deletes the application (the token is removed) - The user install the application and again receives the token and sends it to the server
The question, as I understand on the server that the user is now a new marker?
Can I in this case relies on the canonical id?
If so, why do I get the response value canonical_ids: 0 instead of 2
For example:
{ multicast_id: 8398272353674231000,
success: 3,
failure: 2,
canonical_ids: 0,
results:
[ { message_id: '0:1462880284140861%5dee2b8a5dee2b8a' },
{ message_id: '0:1462880284140859%5dee2b8a5dee2b8a' },
{ error: 'NotRegistered' },
{ message_id: '0:1462880284140863%5dee2b8a5dee2b8a' },
{ error: 'NotRegistered' } ] }
My code for requests GCM server
http = require('http');
var request = require('request');
os = require('os');
var mGcmUsers = [];
var interfaces = os.networkInterfaces()
var addresses = []
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family == 'IPv4' && !address.internal) {
addresses.push(address.address)
}
}
}
//gcm variables
var API_KEY = "MyKey";
/******************************** HTTP SERVER *************************************/
http.createServer(function (req, res) {
if (req.method == 'POST') {
console.log('\nHTTP POST');
req.on('data', function (data) {
console.log('gcm user token: ' + data)
});
}
if (req.method == 'GET') {
console.log('\nHTTP GET');
}
}).listen(8000, addresses[0]);
console.log('HTTP server running at', addresses[0], ':8000');
var gcm = require('node-gcm');
// Create a message
// ... with default values
var message = new gcm.Message();
// ... or some given values
var message = new gcm.Message({
collapseKey: 'data',
priority: 'high',
contentAvailable: true,
delayWhileIdle: false,
timeToLive: 10000,
restrictedPackageName: "com.my.project",
// dryRun: true,
data: {
message: 'Message from gcm server',
},
notification: {
title: "Hello, World",
icon: "ic_launcher",
body: "This is a notification that will be displayed ASAP."
}
});
// Set up the sender with you API key
var sender = new gcm.Sender(API_KEY);
// Add the registration tokens of the devices you want to send to
var registrationTokens = [];
registrationTokens.push('e-nzMnczgAc:APA91bH7lVRdY4Vgo3rIwzl4VJNQzmMXeCp5KogXb88WlpU-G7QLUTm41o9h8qMJdpWHXidW0Up6fnPJxypFaqsQGAj4UeuCGfFMFeFOrZLislgKU6dWyj3rmFTkPo9k4PCIxn3zAm3p');
registrationTokens.push('cxC0GdUP38k:APA91bFi_Rkf2vStLphQI-FRQxdT9QWbAOg593j2M4XKBtgesIQnZJ9w2MR_Uajj9oOjirIlYLMJQgzkrgN1hOUkA3iqrPxQ3cvu64jbluyP9Zy1Q73q4cCCribIrvcfu34sOWbyF1YP');
registrationTokens.push('eGrXkmmOv3o:APA91bHx_Xdua6_2emJSY2t48a12ZLNruJkP8cTg-DUGOfFzF7N8Rm0DE0SUUiMzqyPCuaMKWWRW_HGvgicRrm_hXXinWAXP2-NYjRqdeBWS3G7CACi64hU-64GsRw34a3-5u3wiJ86G');
registrationTokens.push('eK4vCiFIu40:APA91bHw2HVlZiHCqjh6NrJ-epx5YqJKCf-CcgtO0yXXO_czPKjvozounPZRuE9I-iFzIdQCo3mi9Apr7e9NHCRi-Sv9qzn1xTyeLswv7FJWb_ZESVGDKtQeCPVpDoGwJzGS9FTag3Xv');
registrationTokens.push('dw_zOwn2X-U:APA91bGWuSCPOMsabAvjPzrrFDx8ZoQM-LtE0YKabrDaeShZV31T7Mvh-Mtim4J6X3th8UBgAgqr4OZhYjTcpkyE3J_PdapEhvjf98geqloZL7u_7vaVfLZolQKYwWaO-prTO89pVxpi');
registrationTokens.push('cb3-U8wHXgA:APA91bGx4YTolh4ti4IP7PxzCXqWM9Q1Sb23dQXBq4U5Ftrbf4zgZC0hgay4V2SAptKN4SubJ-3tanf4iiS77uQy4VpLZdtZsu7rUqAHmZ4-p1nGwQU1eIAHc3EZPAA_sN4jSWSq3Of6');
sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
if(err) console.error(err);
else console.log(response);
});