When having multiple regids for 1 device GCM returns the canonical id error:
{"multicast_id":xxxx,"success":2,"failure":0,"canonical_ids":1,"results":[{"message_id":"xxxxx"},{"registration_id":"newest reg ID here","message_id":"xxxxxx"}]}
So it shows the newest regid that should be used by GCM but why isn't it showing the regid that you should delete (the old one)? How do I know what the old regid is and which one I should delete from my database?
A Registration ID is an identifier assigned by GCM to a single instance of a single application installed on an Android device. The device is assigned this identifier when it registers to Google Cloud Messaging. The GCM documentation doesn't specify what information is encoded in this identifier.
Eran's answer is correct, though I found it still a bit foggy for me. However, thanks to him I found a solution.
Say this is your response:
{
"multicast_id":xxxxx,
"success":7,
"failure":0,
"canonical_ids":2,
"results":[
{
"message_id":"0:xxx%xxxxx"
},
{
"message_id":"0:xxx%xxxxx"
},
{
"registration_id":"MY_REG_ID_1",
"message_id":"0:xxx%xxxxx"
},
{
"message_id":"0:xxx%xxxxx"
},
{
"message_id":"0:xxx%xxxxx"
},
{
"registration_id":"MY_REG_ID_2",
"message_id":"0:xxx%xxxxx"
},
{
"message_id":"0:xxx%xxxxx"
}
]
}
As you can see 2 of the 7 messages are a duplicate.
This is the way I send messages to the server:
$tokenResult = mysql_query("SELECT reg_ids FROM table_with_regids"); //
$i = 0;
while($row = mysql_fetch_array($tokenResult)) {
$registrationIDs[$i] = $row['reg_ids'];
$i++;
}
from Eran's answer:
Since you get a response from Google for each request you send, you should know which Registration IDs were sent to Google in the request that triggered this response. The old Registration ID that you have to delete is the second Registration ID in that request.
This means that index 2 and 5 of the array $registrationIDs[] should be replaced with MY_REG_ID_1 and MY_REG_ID_2.
Finally check for double values and remove the exact duplicates. The result should be an array with 5 regids (or directly delete that index from your array instead of replacing with MY_REG_ID_#).
The GCM response you included indicates that you sent a message to two Registration IDs. Both messages were received in the GCM service successfully. Only for the second message you got a canonical Registration ID.
Since you get a response from Google for each request you send, you should know which Registration IDs were sent to Google in the request that triggered this response. The old Registration ID that you have to delete is the second Registration ID in that request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With