CrossGeeks/FirebasePushNotificationPlugin

Current.Token invalid after restarting app, token not refreshed

goatrodeosoftware opened this issue ยท 1 comments

๐Ÿ› Bug Report

I can successfully get a token and send a message to it- I'm using Postman to eliminate variables. I send this body:
{
"to": "{token}",
"priority" : "high",
"notification" : {
"body" : "Body of Your Notification?",
"title": "Title of Your NotificatioN"
}
}
and receive successful responses on any number of messages until I restart the app, including after I close the app, for at least several minutes. On the restart, somewhere between Application.OnCreate, where the token works on a breakpoint on the very last line, and MainApplication.OnCreate, whereupon hitting a breakpoint at the beginning results in
{
"multicast_id": 2641009285763831713,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered"
}
]
}
I'm wired up to the OnTokenRefresh issue, and I manually check it on logging in, but I still have the same token- it's just apparently no longer valid. Something between the two OnCreate methods invalidates it. I've tried rolling with it, but calling FirebasePushNotificationManager.Reset() at the beginning and end of both on create methods doesn't seem to reset it. I did research this for several hours, but please forgive me if it's been answered elsewhere. My MainApplication.OnCreate:
base.OnCreate();
RegisterActivityLifecycleCallbacks(this);
FirebasePushNotificationManager.RegisterUserNotificationCategories(new NotificationUserCategory[]
{
new NotificationUserCategory("AcceptReject",new List {
new NotificationUserAction("Accept","Accept"),
new NotificationUserAction("Reject","Reject")

            }),
            new NotificationUserCategory("Acknowledge",new List<NotificationUserAction> {
                new NotificationUserAction("OK", "OK", NotificationActionType.Destructive)
            })
        });
        //If debug you should reset the token each time.

#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this, false);
#endif
and MainActivity.OnCreate:
PayCardsRecognizerService.Initialize(this);
UserDialogs.Init(this);
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, bundle);
App app = new App(new AndroidInitializer());
Xamarin.Essentials.Platform.Init(this, bundle);
AndroidAppLinks.Init(this);
LoadApplication(app);
FirebasePushNotificationManager.ProcessIntent(this, Intent);

Expected behavior

The token should remain valid in between application starts, or at least an updated token should be refreshed

Reproduction steps

Start the app and grab the token, then restart the app: the token in Current.Token is now invalid and is not refreshed.

Configuration

My MainApplication.OnCreate:
base.OnCreate();
RegisterActivityLifecycleCallbacks(this);
FirebasePushNotificationManager.RegisterUserNotificationCategories(new NotificationUserCategory[]
{
new NotificationUserCategory("AcceptReject",new List {
new NotificationUserAction("Accept","Accept"),
new NotificationUserAction("Reject","Reject")

            }),
            new NotificationUserCategory("Acknowledge",new List<NotificationUserAction> {
                new NotificationUserAction("OK", "OK", NotificationActionType.Destructive)
            })
        });
        //If debug you should reset the token each time.

#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this, false);
#endif
and MainActivity.OnCreate:
PayCardsRecognizerService.Initialize(this);
UserDialogs.Init(this);
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, bundle);
App app = new App(new AndroidInitializer());
Xamarin.Essentials.Platform.Init(this, bundle);
AndroidAppLinks.Init(this);
LoadApplication(app);
FirebasePushNotificationManager.ProcessIntent(this, Intent);

Version: 3.4.25

Platform:

  • ๐Ÿ“ฑ iOS
  • ๐Ÿค– Android
  • ๐Ÿ WPF
  • ๐ŸŒŽ UWP
  • ๐ŸŽ MacOS
  • ๐Ÿ“บ tvOS
  • ๐Ÿ’ Xamarin.Forms

I moved the code that was in my startup activity to the splash activity and I seem to get a new token every time now, which at least solves the symptom.