question

VuyiswaMaseko-8882 avatar image
0 Votes"
VuyiswaMaseko-8882 asked YonglunLiu-MSFT commented

How to Register a device for Push notification and get a Token

i trap the token creation and store it in the db

 [Service(DirectBootAware = true, Exported = false, Enabled = true)]
 [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
 public class CustomFirebaseMessagingService : FirebaseMessagingService
 {
     public override void OnNewToken(string token)
     {
         try
         {
             base.OnNewToken(token);
             GenericMethods.PUSH_TOKEN = token;
             Task.Run(() => GenericMethods.StorePushToken(token));
         }
         catch (Exception ex)
         {
             Crashes.TrackError(ex);
         }
     }

and i have subscribed to the change on the App.cs

     CrossFirebasePushNotification.Current.OnTokenRefresh += Current_OnTokenRefresh;

for some reason some users who register on my app dont have token saved and i dont get an error . Their device are in the supported range of android and non Huawei . I want to manually register the device and get a token , how can i do that programmatically ?

Thanks





dotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·

1 Answer

YonglunLiu-MSFT avatar image
0 Votes"
YonglunLiu-MSFT answered VuyiswaMaseko-8882 commented

Hello,

for some reason some users who register on my app dont have token saved and i dont get an error.

Your code seems no problem, Please check the method GenericMethods.StorePushToken, it would be the reason the error occurs.

manually register the device and get a token

It's no way to set the device token for Firebase Cloud Messaging by yourself. It would actually be an antipattern to set a user's ID, due to the same user may end up using the app on different devices.

Best Regards,

Alec Liu.



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you , you have answered me.

0 Votes 0 ·

@VuyiswaMaseko-8882
I have collated the comment into an answer. Could you please mark it? It will be helpful for others who meet the same issue.:)

0 Votes 0 ·

Thanks its done.

0 Votes 0 ·