Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
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

C#
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
C#
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,
                        //Topic = "TrovaPush",
                        Notification = new Notification()
                        {
                            Title = model.TITLE,
                            Body = model.MESSAGE_BODY,
                            ImageUrl = model.ICON_URL
                        }
                    };

                    // Send a message to the device corresponding to the provided 
                    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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900