Getting Empty token from CrossFirebasePushNotification.Current.Token
🐛 Sometimes I am getting empty token from CrossFirebasePushNotification.Current.Token
Expected behavior
I am expecting and wants new token each time in "userDeviceToken" variable by using below code.
if (string.IsNullOrEmpty(CrossFirebasePushNotification.Current.Token)) { CrossFirebasePushNotification.Current.RegisterForPushNotifications(); await Task.Delay(100); } userDeviceToken = CrossFirebasePushNotification.Current.Token;
Reproduction steps
I am using below code to get the new token each time when user trying to login into the App. I even running the loop 5 times to get the token value but I am getting empty token. This happens only few times.
int tryCounter = 0; bool receivedToken = false; string userDeviceToken = null; while (!receivedToken && tryCounter < 5) { try { tryCounter += 1; if (string.IsNullOrEmpty(CrossFirebasePushNotification.Current.Token)) { CrossFirebasePushNotification.Current.RegisterForPushNotifications(); await Task.Delay(100); } userDeviceToken = CrossFirebasePushNotification.Current.Token; if (string.IsNullOrEmpty(userDeviceToken)) receivedToken = false; else { receivedToken = true; } } catch (Exception e) { Debug.WriteLine(e.Message); } }
In Xamarin.Android project => MainApplication.cs class, I am using below line of code for initializing the plugin.
public override void OnCreate() { base.OnCreate(); FirebasePushNotificationManager.Initialize(this, false); }
In App.xaml.cs class OnStart() method, I have the OnTokenRefresh event
protected override void OnStart()
{
CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
{
Debug.WriteLine($"TOKEN REC: {p.Token}");
};
}
Configuration
Version: 3.3.9
Platform:
- [ ] :monkey: Xamarin.Forms
any updated?
I am also facing same issue, any updates?