为什么GCM文档建议在程序更新的无效注册? [英] why do gcm docs recommend invalidating registration on app update?

查看:127
本文介绍了为什么GCM文档建议在程序更新的无效注册?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从GCM 文档

当一个应用程序被更新时,它应该无效其现有   注册ID的,因为它不能保证与新的版本来工作。   因为没有所谓生命周期方法,当应用程序是   更新,实现此验证的最好方式是通过存储   当注册ID存储当前应用程序的版本。然后   当应用程序启动时,比较所存储的值与所述   当前应用程序的版本。如果它们不匹配,失效   存储的数据并再次启动注册程序。

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. Then when the application is started, compare the stored value with the current application version. If they do not match, invalidate the stored data and start the registration process again.

在文档指出,它不能保证与新版本一起工作是一个GCM限制或者他们猜测我的应用程序的行为版本的潜在变化从版本?

When the docs state that "it is not guaranteed to work with the new version" is that a GCM limitation or are they speculating about potential changes in my app's behavior from version to version?

从应用程序端,我可以更多或更少的保证后续版本将正常运行相对于GCM和我编造任何应用程序特定的消息格式。我还需要重新注册?

From the app side I can more-or-less guarantee that successive versions will function properly with respect to GCM and whatever app-specific message format I concoct. Do I still need to re-register?

如果有,是我应该用它来检测新版本:版本code或版本的名字吗?我的理解是,这是自由表和应用程序开发人员他们设置为他选择的任何值。那么,如果我把一个应用程序更新的存储,但并不改变VERSIONNAME或版本code;我需要重新注册GCM?

If so, which should I use to detect a "new version": version code or version name? My understanding is that these are "free form" and the app developer sets them to whatever values he chooses. So, what if I put an app update in the store but don't change versionName or versionCode; would I need to re-register with GCM?

好像什么GCM 实际要的是为应用程序来重新注册一个新的安装启动首次每次(每一次它的相继推出,直到注册完成),而不管在VERSIONNAME和价值观版本code。那是一个准确的说法?

It seems like what GCM actually wants is for the app to re-register each time a new installation is launched for the first time (and each time it's successively launched until registration is complete), regardless of the values in versionName and versionCode. Is that an accurate statement?

推荐答案

我不记得我们读过它,但它来到了我们的注意,当一个设备被一推,而一个应用程序没有安装,谷歌将无效的注册ID。

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.

解决方案似乎是一个更新后的第一次启动重新注册,以确保您的应用程序的注册ID是有效的。

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

版code的确是一个自由选择的号码,但你的必须的增加​​它发布到Google Play上的每一个新版本,这样你就可以检查这个数字发生了变化,并且知道你应用程序已被更新,需要刷新登记。

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.

编辑:

这也关系到 C2DM 的继任 GCM ,有更多​​的文档解释这一行为,以及如何正确地写code。

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

请参阅:<一href="http://developer.android.com/google/gcm/client.html">http://developer.android.com/google/gcm/client.html所有的细节。

具体是这样code,其中 getRegistrationId 将返回一个空字符串的情况下的版本code改迫使客户重新注册:

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.");
        }

这篇关于为什么GCM文档建议在程序更新的无效注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆