Reputation: 19
So I got my app running and notification works fine at first. But after a while it just stopped.
I tried sending through the Firebase console and it returns success, but no notification was received by the application. The application was in background, and it worked earlier, no code has been changed on either the app or the server side.
If I reinstalled the app (getting a new token), the notification would return to normal (working as intended), but if the token expires shouldn't the Firebase console return an error (registration token error or something)?
And it has only been a few days since I used the application, so why would the token expires (documentation said token would expire in 6 months)? And I know it is a bad approach to actually force a token refresh every time a user runs my app.
So did I do something wrong? Cause if I debug my app everything works fine. Got the token, got the notification.
And yeah, sending notification through FCM console and via server yield the same result; success, but no notification.
the onTokenRefresh code looklike this :
namespace FCMClient
{
[Service]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService
{
const string TAG = "MyFirebaseIIDService";
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
SendRegistrationToServer(refreshedToken);
}
void SendRegistrationToServer(string token)
{
//a post request to my server
}
}
}
Thanks for any insight.
Upvotes: 1
Views: 2226
Reputation: 164
Adding the debug fingerprint in Firebase console seems to do the trick.
Upvotes: 0
Reputation: 11
This always happens to my, it's a kind of bug or something, i have to clean and rebuild every time, this not happen on release, you can delete the firebase instance and get a new token everytime you run the application while you'r debugging.
you can write this on you oncreate
Task.Run(() => {
var instanceid = FirebaseInstanceId.Instance;
instanceid.DeleteInstanceId();
Log.Debug("TAG", "{0} {1}", instanceid.Token, instanceid.GetToken(this.GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope)); });
Upvotes: 1