I am developing a phonegap app and followed this tutorial to implement PushPlugin. However, it says to register the app every time deviceready event is triggered. This means that it'll register the device on GCM even if it'd been previously registered.
This made me a little bit uncomfortable as it doesn't seem to be a good practice, since the device was already registered, so, I decided to come here to ask. Is this a good practice? If not, why? Do this have some long term complication?
In our application we have found this to be a good practice for several reasons:
The API for registering the device returns a token that represents that device. From what I could see, GCM does not guarantee that the token will remain valid indefinitely. Thus failure to register could lead to expiration of your device token.
Registering with GCM, makes the service aware that your device is active. From what we observed, devices recently registered with GCM seemed to receive push notifications fastest. That is, given 2 devices, one recently registered (Device A), and the other that had last registered several days ago (Device B), Device A would always receive push notifications faster - often minutes before Device B. This is simply what we observed.
In Google's official GCM Client Demo App they register to GCM only when a new version of the application is installed on the device. Therefore I assume that's the best practice.
That said, registering every time the app starts ensures the your server gets the Registration ID even if it lost it somehow, but that shouldn't be an issue if your Registration IDs are persisted properly in the server.
The problem with GCM is that it doesn't last forever, but time is not your biggest constraint. If you don't want to register every time there are several events that you have to watch that will cause the token to be invalidaded, some of them are:
- Every time the app is updated
- When the phone restarts
- A few days without notifications(Not so sure, but seems to be true on my case)
My advice: Register as often as you want, if that is a problem than you fix it. I would say keeping track of the token to see if it is still valid is too much work.