why do gcm docs recommend invalidating registration on app update?

前端 未结 2 1076
渐次进展
渐次进展 2021-02-14 15:24

From the GCM docs:

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

相关标签:
2条回答
  • 2021-02-14 16:18

    I don't remember where we've read it, but it came to our attention that when a device gets a push while an app is not installed, Google will invalidate the registration id.

    This makes sense if the app is really uninstalled, but if the device was actually in the middle on an update, it quickly uninstalls and re-installs, so google might mistakenly think the registration needs to be invalidated.

    The solution seems like to re-register on the first launch after an update, to guarantee your app registration id is active.

    Version code is indeed a freely selected number, but you must increase it on every new version you publish to google play, so you can check if that number has changed, and know your app had been updated and you need to refresh the registration.

    EDIT:

    This is also relevant to C2DM's successor GCM, with a lot more docs explaining this behavior and how to properly write code.

    See: http://developer.android.com/google/gcm/client.html with all the details.

    Specifically this code, where getRegistrationId will return an empty string in case the version code changed forcing the client to register again:

            if (checkPlayServices()) {
                gcm = GoogleCloudMessaging.getInstance(this);
                regid = getRegistrationId(context);
    
                if (regid.isEmpty()) {
                    registerInBackground();
                }
            } else {
                Log.i(TAG, "No valid Google Play Services APK found.");
            }
    
    0 讨论(0)
  • 2021-02-14 16:30

    I would use the Version Code to detect the app update. The Version Code is forced to change every time you submit a new version to the Google Play store, hence you can rely on it to detect the app's version.

    0 讨论(0)
提交回复
热议问题