We're using Firebase Cloud Messaging for delivering push notifications.
Recently, I started seeing that the push notifications are delivered twice to the same device.
When I dug deeper, I found out that in our backend one device is registered with 2 firebase tokens. And both of them are working. Therefore, the device token provided by iOS must not have changed.
As per GCM documentation, this could happen due to a bug in the client:
Canonical IDs
If a bug in the client app triggers multiple registrations for the same device, it can be hard to reconcile state and the client app might end up with duplicate messages.
Implementing canonical IDs can help you more easily recover from these situations. A canonical registration ID is the registration token of the last registration requested by the client app . This is the ID that the server should use when sending messages to the device.
If you try to send a message using an old registration token, GCM will process the request as usual, but it will include the canonical ID in the registration_id field of the response. Make sure to replace the registration token stored in your server with this canonical ID, as eventually the old registration token will stop working.
So in case that we send a push notification to the old token, we should get a response with registration_id key value pair in it.
FCM documentation describes this case in more detail:
If
message_idis set, check forregistration_id:If
registration_idis set, replace the original ID with the new value (canonical ID) in your server database. Note that the original ID is not part of the result, so you need to obtain it from the list ofregistration_idspassed in the request (using the same index).
However, there's no registration_id in the response when using any of the two working tokens. So it seems FCM is not aware that the device is registered with multiple tokens and therefore does not include registration_id in the response.
The response looks like this:
{
"multicast_id": 9087190295926530487,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [{
"message_id": "0:1498726709849471%10726fcd10726fcd"
}]
}
My question is: Is there any way how to get canonical ids for all devices that are registered in FCM and have multiple tokens? Or what would be the recommended way to fixing a problem like this?