Android Token never refreshed
See original GitHub issueIf you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.
Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.
Bug Information
Version Number of Plugin:
- 2.3.0
Device Tested On:
- Samsung Galaxy S5 SM-G900I (Android 6.0.1)
- HUAWEI T1 7.0 (Android 4.4.2)
Version of VS:
- Mac 7.4.3
Version of Xamarin:
- Android 8.2.0.16
Versions of other things you are using:
- Xamarin Forms 2.5.0.12223
- Xamarin.GooglePlayServices.* 60.1142.0
Steps to reproduce the Behavior
Call FirebasePushNotificationManager.Initialize(this, true, true, false);
Unable to produce any other behaviour on Android,
Expected Behavior
Token is refreshed on every app launch.
Actual Behavior
- OnTokenRefresh is never called
- CrossFirebasePushNotification.Current.Token is not null but never changes after first install, resulting in “NotRegistered” when trying to push to device using FCM API.
Code snippet
In application OnCreate()
FirebasePushNotificationManager.Initialize(this, true, true, false);
After user login
if (CrossFirebasePushNotification.Current.Token != null) {
RefreshToken(CrossFirebasePushNotification.Current.Token);
}
CrossFirebasePushNotification.Current.OnTokenRefresh += (source, data) => {
if (data != null) {
RefreshToken(data.Token);
}
};
CrossFirebasePushNotification.Current.OnNotificationReceived += (source, data) => {
if (data != null) {
ReceiveNotification(data.Data);
}
};
CrossFirebasePushNotification.Current.OnNotificationOpened += (source, data) => {
if (data != null) {
OpenNotification(data.Data);
}
};
CrossFirebasePushNotification.Current.RegisterForPushNotifications();
Screenshots
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Try initialize with this:
Very nice library @rdelrosario! Many thanks.
@mea-licensing I’ve had a similar issue caused by a combination of issues. 1) I had to have the linker keep
PNFirebaseMessagingService
or else the service was linked out and I’d never get a new token. 2) I do not get a new token every time on startup, but somehow my token expired really quickly, so the existing one inCrossFirebasePushNotification.Current.Token
was never refreshed, which is likely due to 1. I’m currently using a combination of manually usingFirebaseInstanceId.Instance.GetToken...
for the initial registration, and then this plugin for everything else.