I got unregistered registration token even I am sure my token is correct and I check it in my log I am using master token FirebaseInstanceId.Instance.Token
.
Here is my method:
private void ConfigureFireBase()
{
Task.Run(() => {
var instanceId = FirebaseInstanceId.Instance;
Android.Util.Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));
});
}
I check as well OnTokenRefresh
method the same token
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
SendRegistrationToServer(refreshedToken);
}
but when I tried in Firebase console it gives me this error message, when I tried in http://pushtry.com/ with the same token I got not NotRegistered message
Note when I uninstall the app and install again the token working, but after while I got this error message.
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. This is the token that you must include in targeted send requests from the API, or add to topic subscriptions for targeting topics.
You need to call sendRegistrationToServer() method which will update token on server, if you are sending push notifications from server. UPDATE: New Firebase token is generated ( onTokenRefresh() is called) when: The app deletes Instance ID.
Firebase gives you complete control over authentication by allowing you to authenticate users or devices using secure JSON Web Tokens (JWTs). You generate these tokens on your server, pass them back to a client device, and then use them to authenticate via the signInWithCustomToken() method.
It doesn't expire though. It renews itself if one of the following happens. According to https://firebase.google.com/docs/cloud-messaging/android/client: -The app deletes Instance ID.
The reason why this issue fired cause that token is unregistered
The registration token may change when: The app deletes Instance ID The app is restored on a new device The user uninstalls/reinstall the app The user clears app data.
Reference
and this happen in debug mode only so dont worry in release mode every thing will be fine.
How you can fix the issue ?
its easy just force to refresh token call this method in your landing activity (MainActivity , Login ) , this method force firebase to call OnTokenRefresh()
private void ConfigureFireBase()
{
#if DEBUG
Task.Run(() =>
{
var instanceId = FirebaseInstanceId.Instance;
instanceId.DeleteInstanceId();
Android.Util.Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));
});
// For debug mode only - will accept the HTTPS certificate of Test/Dev server, as the HTTPS certificate is invalid /not trusted
ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
#endif
}
Hope this help any one face same issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With