rdelrosario / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
179 stars 161 forks source link

OnRegistered triggered only one time (after first execution of the App) #29

Closed aunanue closed 8 years ago

aunanue commented 8 years ago

The OnRegistered method is triggered one time and only after deleting the App and installing it again, if I have the App already installed (and being using it) the OnRegistered is not triggered anymore. Is any way to force it? or tell me if I'm doing something wrong. I have the "Register()" call in the OnStart of the App (Form App).

protected override void OnStart () { // Handle when your app starts CrossPushNotification.Current.Register(); }

rdelrosario commented 8 years ago

Yes is only trigger one time now because stores the token, if you need it to trigger more than once. should unregister. Why would you want to trigger everytime?

aunanue commented 8 years ago

I was expecting to get a new token if that was required. I have this situation: 1) the plugin returns the token the first time, I store this token on the my DB on the cloud. 2) with a service on the cloud that has no connection at all with the App I send the Push messages using PushSharp. In some cases the token returned by the plugin expires therefore I need a new one. 3) at this point I was expecting to receive a new token by the plugin but if I understand properly, I will have to do a sort of communication between the cloud and the App to do the "Plugin.Unregister()" when the PushSharp receives the expired token exception because the plugin does not checks the validity of the current token on the Plugin.Register() method.

In the mean time, can I call the Unregister() followed by the Register()? do you see a problem on this as follows: protected override void OnStart () { // Handle when your app starts CrossPushNotification.Current.Unregister(); CrossPushNotification.Current.Register(); }

MKahmen commented 8 years ago

same issue for me. after updating the app in Xamarin Studio, GCM/PushSharp says the device token is expired. I have to either:

  1. uninstall the whole app and reinstall again (which is not a good idea)
  2. call unregister() each time I open the app to make sure the app gets a new token which is not expired (very dirty)

any ideas?

EDIT: https://github.com/rdelrosario/xamarin-plugins/issues/28

http://stackoverflow.com/questions/11590482/do-gcm-registration-ids-expire

When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version. Because there is no lifecycle method called when the application is updated, the best way to achieve this validation is by storing the current application version when a registration ID is stored.

rdelrosario commented 8 years ago

Now calls OnRegistered each time gets registered by Register method