In some cases OnTokenRefresh is not called or called twice when a update with a new build number has been installed
🐛 Bug Report
On some devices (Galaxy S10+) in some cases the app doesn't get a new token with a changed build number, or OnTokenRefresh is called twice, with two different tokens. If OnTokenRefresh is not called, CrossFirebasePushNotification.Current.Token still is the same after starting the app and doesn't change on next starts. But the token has been changed, becauce on the server the firebase result is NotRegistered for sending a message to the device.
Expected behavior
OnTokenRefresh is called once, if ResetToken=true or with a new build number is given.
Reproduction steps
Not able to reproduce it every time, only in some cases
Configuration
Version: 3.1.6
Platform:
- [ ] :iphone: iOS
- [x] :robot: Android
- [ ] :checkered_flag: WPF
- [ ] :earth_americas: UWP
- [ ] :apple: MacOS
- [ ] :tv: tvOS
- [ ] :monkey: Xamarin.Forms
It may have something to do with this issue (GetTokenAsync race condition #316).
@Freddyvdh set event error, look idf you thorw this error:
Java.IO.IOException: SERVICE_NOT_AVAILABLE at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <26521a5118b44c858c385715922b9d5d>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <26521a5118b44c858c385715922b9d5d>:0 at Firebase.Iid.FirebaseInstanceId.DeleteInstanceId () [0x00000] in D:\a\1\s\generated\com.google.firebase.firebase-iid\obj\Release\monoandroid90\generated\src\Firebase.Iid.FirebaseInstanceId.cs:158 at Plugin.FirebasePushNotification.FirebasePushNotificationManager.CleanUp (System.Boolean clearAll) [0x00012] in <4a9f9b43b74b4a9fb9bd18b7778c2743>:0 at Plugin.FirebasePushNotification.FirebasePushNotificationManager+<>c__DisplayClass63_0.<Initialize>b__0 (System.Object state) [0x000f4] in <4a9f9b43b74b4a9fb9bd18b7778c2743>:0 --- End of managed Java.IO.IOException stack trace --- java.io.IOException: SERVICE_NOT_AVAILABLE at com.google.firebase.iid.FirebaseInstanceId.zza(Unknown Source:95) at com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId(Unknown Source:71)
Thanks for your response.
I have added a event handler for CrossFirebasePushNotification.Current.OnNotificationError but it is not called.
I'm still not using AndroidX in my project as you mentioned in your issue #318. I'm still on Xamarin Forms 4.5
I can reproduce the problem with a simulator (Pixel 3a XL Q 10.0 - API 29). I have updated to the latest version and the problem still occurs.
In MainApplication the event handler are assigned: `public override void OnCreate() { base.OnCreate();
CrossFirebasePushNotification.Current.OnNotificationError += this.Current_OnNotificationError; CrossFirebasePushNotification.Current.OnNotificationReceived += this.Current_OnNotificationReceived; CrossFirebasePushNotification.Current.OnTokenRefresh += this.Current_OnTokenRefresh;
FirebasePushNotificationManager.Initialize(this, new PushNotificationHandler(), resetToken, createDefaultNotificationChannel: false, autoRegistration: true); }`
On the simulator TokenChangedHandler is called twice with too different tokens.
Even, if FirebasePushNotificationManager.Initialize is commented out, the TokenChangedHandler is called once.
Maybe there is a blocking on the Galaxy S10+, because of the device performance.
For a workaround I start a timer with a 15 seconds delay to call Initialize, when the firebase token will be reset by the plugin (new package name or new version #319)
One thing I forgot: You need to uninstall the app on the simulator or to change the app version.
One thing I forgot: You need to uninstall the app on the simulator or to change the app version.
This was the answer to my issue #461
Have been struggling for 2 days to find a bug that apparently does not exist.
Turns out you have to delete the App every time for the OnTokenRefresh to be triggered successfully on every Debug session.