Good Day All
i have a Xamarin App , i want to implement Push Notification. i use FirebaseAdmin to send this notifications to a specific user.
When the app loads for the first time i trap the token and store it in the database and in my app.cs i also subscribed to the notification refresh event so i trap the changes of the device token as it changes.
CrossFirebasePushNotification.Current.OnTokenRefresh += Current_OnTokenRefresh;
and in this event i go and update the token on the db.
i created a webapi that can be called by the app to send push notification , i hardcoded the token by copying it from the db table and my app is on release mode on the emulator
on the web api i called it via Fiddler which a different project and debugged it to check if there is any other issues , everything gets executed correctly with no issues except the last line
string response = FirebaseMessaging.DefaultInstance.SendAsync(message).Result;
and it gaves me an error
"FirebaseMessagingException: The registration token is not a valid FCM registration token"
and the example code that tries to sent the Push notification is as below
try
{
PUSH_MESSAGE model = new PUSH_MESSAGE();
model.SENDER_HANDLE = "vuyiswamb";
model.RECEIVER_TOKEN = "e-itrrcdtoodv7rkx6g2yy:apa91bfu1hczrzpaubya9umv3d3guzt_dcz8zhfgbxaltse4fbamcv2kklf6ekdmxhg_g9inwamja8-6vfzfrlqkpm8mi956ncfcsa-jrsmp50qsbblehgiz9ezo7ih3h1aavrodl_jn";
model.SENDER_USER_ID = 1;
model.TITLE = "Hello Girl";
model.MESSAGE_BODY = "How this is working";
model.SENDER_USER_TOKEN = new Guid("84819756-A839-45A0-ACB3-08BCAADAD3BB");
if (model.SENDER_USER_TOKEN != new Guid("00000000-0000-0000-0000-000000000000"))
{
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile(System.Web.Hosting.HostingEnvironment.MapPath(@"~/private_key.json"))
});
var registrationToken = model.RECEIVER_TOKEN;
var message = new Message()
{
Data = new Dictionary<string, string>()
{
{ "SENDER_USER", model.SENDER_USER_ID.ToString() },
},
Token =registrationToken,
Notification = new Notification()
{
Title = model.TITLE,
Body = model.MESSAGE_BODY,
ImageUrl = model.ICON_URL
}
};
string response = FirebaseMessaging.DefaultInstance.SendAsync(message).Result;
}
}
catch (Exception ex)
{
throw ex;
}
The Token is the latest i have in the database
Thanks
What I have tried:
i tried to check if there is another token that is refreshed that i am not trapping in the app.cs but i realized that i have catered for properly