I am using the new GCM APIs in order to register. The documentation of the method clearly states:
我正在使用新的GCM API进行注册。该方法的文件明确指出:
Register the application for GCM and return the registration ID. You must call this once, when your application is installed, and send the returned registration ID to the server.
注册GCM申请并返回注册ID。安装应用程序时,必须调用一次,并将返回的注册ID发送到服务器。
Repeated calls to this method will return the original registration ID.
重复调用此方法将返回原始注册ID。
However, while reading this article (https://developer.android.com/google/gcm/adv.html#reg-state), it states that there are two cases that need special treat:
但是,在阅读本文(https://developer.android.com/google/gcm/adv.html#reg-state)时,它指出有两种情况需要特殊处理:
There are also two other scenarios that require special care:
还有另外两种情况需要特别小心:
- Application update
- Backup and restore
备份还原
When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version.
更新应用程序时,它应使其现有注册ID无效,因为不能保证它与新版本一起使用。
So, it not clear when the developer should invalidate or not the registration ID.
因此,不清楚开发人员何时应该使注册ID无效。
Moreover, regarding the unregister phase the new GCM API states:
此外,关于取消注册阶段,新的GCM API指出:
Unregister the application. Calling unregister() stops any messages from the server. This is a blocking call—you shouldn't call it from the UI thread. You should rarely (if ever) need to call this method. Not only is it expensive in terms of resources, but it invalidates your registration ID, which you should never change unnecessarily. A better approach is to simply have your server stop sending messages. Only use unregister if you want to change your sender ID.
取消注册该应用程序。调用unregister()会停止来自服务器的任何消息。这是一个阻塞调用 - 你不应该从UI线程调用它。您应该很少(如果有的话)需要调用此方法。它不仅在资源方面很昂贵,而且还会使您的注册ID无效,您不应该不必要地更改注册ID。更好的方法是让服务器停止发送消息。如果要更改发件人ID,请仅使用取消注册。
However the previous same article states:
然而,前一篇文章指出:
Whenever the application registers as described in Implementing GCM Client, it should save the registration ID for future use, pass it to the 3rd-party server to complete the registration, and keep track of whether the server completed the registration. If the server fails to complete the registration, it should try again or unregister from GCM.
每当应用程序按照实现GCM客户端中的描述进行注册时,它应该保存注册ID以供将来使用,将其传递给第三方服务器以完成注册,并跟踪服务器是否完成注册。如果服务器无法完成注册,则应再次尝试或从GCM取消注册。
This is also not clear (i.e. how to handle unregistration).
这也不清楚(即如何处理注销)。
Finally, based on the above, it is not clear how Canonical IDs are related to the mobile. In case Google produce a Canonical ID for an existing registration and pass it back to the application backend, it will also change the registration ID of the mobile if it calls the register method? Is there any other way for the mobile to get informed about this new ID?
最后,基于上述内容,尚不清楚Canonical ID如何与移动设备相关。如果Google为现有注册生成Canonical ID并将其传递回应用程序后端,如果它调用了register方法,它还会更改移动设备的注册ID吗?移动设备是否有其他方式可以获得有关此新ID的信息?
Thank you very much in advance!
非常感谢你提前!
1 个解决方案
#1
2
Google suggest that your app should invalidate the registration ID when the app is launched after a new version is installed. Their GCM demo app implements this suggestion. Other than this case, there is no need to call the register method more than once (when the app is first launched).
Google建议在安装新版本后启动应用时,您的应用应使注册ID无效。他们的GCM演示应用程序实现了这个建议。除了这种情况,不需要多次调用寄存器方法(当应用程序首次启动时)。
As for unregistering - they suggest to unregister if your wish to change your sender ID, or if the registration in your own server failed. The reason for the latter is that if your server never got the registration ID from your app, it will never use that registration ID, and therefore there is no reason for the app to be registered to GCM (unless your app is going to retry later to send the registration ID to your server).
至于取消注册 - 如果您希望更改发件人ID,或者您自己的服务器中的注册失败,他们建议取消注册。后者的原因是,如果您的服务器从未从您的应用程序获得注册ID,它将永远不会使用该注册ID,因此没有理由将该应用程序注册到GCM(除非您的应用程序稍后将重试将注册ID发送到您的服务器)。
As for canonical registration ID, the only way I know how to cause a canonical registration ID to be returned to my server is by unregistering the app from GCM (to invalidate the old registration ID) and then re-registering to get a new registration ID. In that scenario, if the server used the old registration ID, it will work, but the new registration ID will be returned as canonical registration ID. That's one of the main reasons for the suggestion not to unregister unnecessarily (to avoid generating multiple registration IDs for the same app on the same device).
对于规范注册ID,我知道如何使规范注册ID返回到我的服务器的唯一方法是从GCM取消注册应用程序(使旧注册ID无效),然后重新注册以获取新的注册ID 。在这种情况下,如果服务器使用旧的注册ID,它将起作用,但新的注册ID将作为规范注册ID返回。这是建议不要不必要地注销(避免在同一设备上为同一个应用程序生成多个注册ID)的主要原因之一。
Since the new registration ID is created as a result of actions you take in the client side (i.e. unregister + register), your app should already be aware of the new registration ID (yes, register will return the latest registration ID, which is identical to the canonical registration ID), and your server should be notified of it and avoid sending messages with the old registration ID in the first place. Getting the canonical registration ID in the response from Google only covers the case in which your client failed to pass the new registration ID to your server (or your server failed to remove the old registration ID). Therefore the is no need to inform the client of the new registration ID.
由于您在客户端采取的操作(即取消注册+注册)创建了新的注册ID,您的应用程序应该已经知道新的注册ID(是的,注册将返回最新的注册ID,这是相同的对于规范注册ID),应该通知您的服务器,并避免首先发送带有旧注册ID的消息。在Google的回复中获取规范注册ID仅涵盖客户未能将新注册ID传递到服务器的情况(或者您的服务器未能删除旧的注册ID)。因此,无需通知客户新的注册ID。
You can read more here about handling registration ID changes and here about canonical registration ID.
您可以在此处阅读有关处理注册ID更改的更多信息,以及此处有关规范注册ID的信息。