Good Day All
I am using Firebase in Xamarin , i have the following situation ,
i have a Token that is receiving an error "UNREGISTERED" as i trapped it via exception handling as depicted below
catch (Exception ex)
{
var error = (FirebaseMessagingException)ex;
if (error.MessagingErrorCode.ToString().ToUpper() == "UNREGISTERED")
{
UnRegisterToken(model.SENDER_USER_ID);
}
else if (error.MessagingErrorCode.ToString().ToUpper() == "INVALID_ARGUMENT")
{
UnRegisterToken(model.SENDER_USER_ID);
}
else if(error.MessagingErrorCode.ToString().ToUpper() == "QUOTA_EXCEEDED")
{
Crashes.TrackError(ex);
}
else if (error.MessagingErrorCode.ToString().ToUpper() == "THIRD_PARTY_AUTH_ERROR")
{
Crashes.TrackError(ex);
}
else
{
Crashes.TrackError(ex);
}
}
if its unregistered , i clear the database token for that user . my challenge is the following
1) When will the next token be generated without the app data being cleared
and obviously on the Android side , i have the part that normally get a new token for the device when its first used like this
[Service(DirectBootAware = true, Exported = false, Enabled = true)]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class CustomFirebaseMessagingIIService : 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 the on Xamarin form App.cs i alsos subscribe to it like this
CrossFirebasePushNotification.Current.Subscribe("Push");
CrossFirebasePushNotification.Current.OnTokenRefresh += Current_OnTokenRefresh;
and store it on the server like this
private void Current_OnTokenRefresh(object source, FirebasePushNotificationTokenEventArgs e)
{
ChangeUserOneSignalID(e.Token);
}
i read the Firebase Documentation that the Token can take 2 months to expire , but this one is fairly new i created it two hours ago . but it seems like it gives an error like that when i try to send a push notification. is it a good idea to clear or and when will it be generated again if its no longer active for the device.
Thanks