Ciprian Dragoe
Ciprian Dragoe

Reputation: 339

Confirm firebase message was received

I have a c# project sending firebase messages via http post to clients having ios and android.

When clients uninstall my app their firebase device IDs are not deleted from my database unfortunately.

The next time I send a message to the device id witch corresponds to an user who uninstalled my app, of course the message is not delivered. Is there any way to know if the message was not delivered ? Unfortunately the response is always successful even if the message is not delivered.

My current code:

var firebaseMessage = new FirebaseMessage();
firebaseMessage.data = notificationMessages;
firebaseMessage.to = device.DeviceRegistrationId; <-- maybe this device is no longer valid
firebaseMessage.priority = "high";
firebaseMessage.notification = new ExpandoObject();
firebaseMessage.notification.title = "myApp";
firebaseMessage.notification.body = "testMessage";
firebaseMessage.notification.sound = "default";
firebaseMessage.notification.click_action = "FCM_PLUGIN_ACTIVITY";
firebaseMessage.notification.icon = "fcm_push_icon"; 
firebaseMessage.notification.delivery_receipt_requested= true;

var client = new HttpClient();
var appKey = "key=" + ApplicationConfig.FirebasKey;
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", appKey);

var response = await client.PostAsJsonAsync("https://fcm.googleapis.com/fcm/send", message);

return response;

Upvotes: 0

Views: 1184

Answers (1)

AL.
AL.

Reputation: 37778

When your app is uninstalled from a device, the corresponding registration token would then be invalidated by the FCM server, so any messages sent to that specific token would result to a NotRegistered response (also see my post here). In that event, you could proceed with deleting the token (or archiving it).

If your use-case intentionally wants to know if the message was received on the client side, you're gonna have to implement Delivery receipts.

Upvotes: 2

Related Questions