Why re-register to gcm when application gets updat

2019-05-21 08:24发布

问题:

I am using gcm in my application. In Google Developers Console page, I created a project and obtained a project id:

Using this project id in my application, the user gets registered to the gcm servers and obtain a registeration id. Then it is sent to my 3rd party server to be stored.

When 3rd party server wants to send message to the user, it uses the apikey I've obtained in the Google Developer Console page in the header of the post action and uses ther registeration id that has been stored for this particular user. The api key I'm using is from:

Please note that it's the key for server applications and the way i'm using this information is as just as I explained.

Everything works fine, messages are retrieved by the correct users and so on.I'm planning to deploy my app on google play but what is written in the section:GCM advanced topics confuses me. it says :

When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version

and on the comment section of the sample code in Implementing GCM client sample code there is this comment:

// Check if app was updated; if so, it must clear the registration ID
// since the existing regID is not guaranteed to work with the new
// app version.

What is meant by these two explanations? I thought unless I press regenerate key here:

my api key wouldn't change. Why should it (or does it really) change when I update my application? or am I getting something wrong?

回答1:

You are mixing between two different terms - API key and Registration ID. You don't have to create a new API key when deploying a new version.

What Google recommend to do (in the quotes you included above) is to re-register each device that installs the new version to GCM (and not rely on a previously obtained Registration ID), because the existing Registration ID assigned to the device for your application is not guaranteed to work for the new version of the app.