iOS: OnTokenRefresh will NEVER fire if autoRegistration=false
Hi there,
great plugin, thanks.
Quick question.
I assume that OnTokenRefresh Event:
CrossFirebasePushNotification.Current.OnTokenRefresh += (s,p) => { System.Diagnostics.Debug.WriteLine($"TOKEN : {p.Token}"); };
Is only called when the token gets refreshed and NOT when the app is launched / token is initially generated?
Would the correct method be to check for and save the initial token on app launch using
CrossFirebasePushNotification.Current.Token
In the RegisteredForRemoteNotifications override of AppDeligate on iOS?
Thanks
So on further investigation, it appears that OnTokenRefresh event is called on Android after initially registering for notifications, but is NOT called on iOS after initially registering for notifications.
Therefore I am assuming that on iOS the correct procedure is to update the token to the remote server in RegisteredForRemoteNotifications and OnTokenRefresh
Would be greatful is someone else could confirm this behaviour? Thanks
You should save it just on OnTokenRefresh event
Hi @rdelrosario - I've done some further investigation, and have found the issue.
Using plugin 3.1.6 on iOS 13.4 does NOT call OnTokenRefresh if the plugin is initialised as:
FirebasePushNotificationManager.Initialize(options, autoRegistration: false);
Even if at a later date you call CrossFirebasePushNotification.Current.RegisterForPushNotifications(); - OnTokenRefresh will still never be invoked.
However if you initialise the plug in as:
FirebasePushNotificationManager.Initialize(options);
The whole plugin works as expected on iOS and OnTokenRefresh is called as expected.
So the bug is with the autoRegistration argument on iOS being set to false.
Hope this helps.
So I was having a read here: https://github.com/xamarin/GoogleApisForiOSComponents/blob/master/docs/Firebase/CloudMessaging/GettingStarted.md#about-firebase-cloud-messaging
It says that if you add in
<key>FirebaseMessagingAutoInitEnabled</key> <false/>
To your Info.plist - that should disable registration by default.
However it doesn't.....!
In our case we had to do this to fix the issue:
Messaging.SharedInstance.Delegate = CrossFirebasePushNotification.Current as IMessagingDelegate;
FirebasePushNotificationManager.Initialize(options, false);
In our case we had to do this to fix the issue:
Messaging.SharedInstance.Delegate = CrossFirebasePushNotification.Current as IMessagingDelegate; FirebasePushNotificationManager.Initialize(options, false);
If this works - you will have solved the only outstanding issue we have with this library! Thanks - will test hopefully this weekend and report back.
This works for me:
..
FirebasePushNotificationManager.Initialize(options, false);
Messaging.SharedInstance.AutoInitEnabled = true;
Messaging.SharedInstance.Delegate = CrossFirebasePushNotification.Current as IMessagingDelegate;
LoadApplication(new App(new iOSInitializer()));
return base.FinishedLaunching(app, options);