I'm looking for a way to handle registrations when user reinstalls an app (Android).
I manage device registration from backend using the installation method. This is the scenario that results in problem for me.
- User start app and call backend to register the device for notifications. Backend is provided with the PNS-handle that is received from FCM.
- The device is registered in backend database and in Azure Notification Hub using the method CreateOrUpdateInstallationAsync(Installation)
The device is now ready to receive notifications and it works fine.
- User uninstalls the app.
- User installs the app again.
- The app calls backend and register the device for notifications again. However there will be a new PNS handle retrieved from FCM than in step 1.
In the Device table in the backend database there are now two lines for the same device. When notifications are being pushed to devices there are two notifications pushed to the same device.
I have read about that you can use canonical_ids available in Firebase Cloud Messaging. However I don't know how I can take advantage of that when I'm using Azure Notification Hub.
NotificationOutcome outcome = await Hub.SendGcmNativeNotificationAsync(notification, tag);
The response is of type NotificationOutcome and in the response I can't see anything that can help me to see if the registration is valid or not.
When I post directly to FCM using https://fcm.googleapis.com/fcm/send I get a response like this which gives me a result that can be used to handle old registrations on the server side.
{
"multicast_id": 4654657432518406292,
"success": 1,
"failure": 0,
"canonical_ids": 1,
"results": [
{
"registration_id": "APA91bHGMrMcVW6QNCgH62LiNIk4b1dd40Loz-aRkQUUKCUJz1HijWS2zIPJ5273dFy62u8hLEVZDBUbv-mU-WYRPF2xHMl2OUnDk73U_gSG9OcnewfQQKTkSupFfOTVG1Q0KDuWB-41",
"message_id": "0:1490359752341398%624ba715f9fd7ecd"
}
]
}