谷歌云消息 - 注册ID状态 [英] Google Cloud Messaging - Registration ID status

查看:288
本文介绍了谷歌云消息 - 注册ID状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以我注册使用新的API GCM。该方法的文件明确规定:

I am using the new GCM APIs in order to register. The documentation of the method clearly states:

注册为GCM应用程序并返回的注册ID。您
  必须再次调用该方法,在安装应用程序时,并发送
  返回注册ID给服务器

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.

此方法重复调用将返回原登记
  ID。

Repeated calls to this method will return the original registration ID.

不过,在阅读这篇文章( http://developer.android .COM /谷歌/ GCM / adv.html#REG-状态),它指出有两种情况需要特别对待:

However, while reading this article (http://developer.android.com/google/gcm/adv.html#reg-state), it states that there are two cases that need special treat:

也有一些需要特殊照顾的其他两种方案:

There are also two other scenarios that require special care:


      
  • 应用程序更新

  •   
  • 备份和恢复

  •   

当一个应用程序更新,应该废止其现有的注册ID,因为它不能保证在新版本的工作。

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.

此外,关于注销阶段,新的GCM API状态:

Moreover, regarding the unregister phase the new GCM API states:

注销申请。调用注销()停止从服务器上的任何消息。这是一个阻塞调用,你不应该从UI线程调用它。你应该很少(如果有的话)需要调用此方法。它不仅是在资源方面昂贵,但它无效您的注册ID,您永远不应该随意改变。更好的方法是简单地让服务器停止发送消息。仅使用,如果你想改变你的发件人ID注销。

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.

然而,previous同一篇文章中指出:

However the previous same article states:

每当作为实施GCM描述的应用寄存器
  客户端,它应该保存以备将来使用的注册ID,它传递给
  在第三方服务器上完成注册,并保持跟踪
  服务器是否完成了登记。如果服务器失败
  完成注册后,就应该再试一次或GCM注销。

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.

这也是不明确的(即如何处理注销)。

This is also not clear (i.e. how to handle unregistration).

最后,根据上述情况,它是不明确的ID如何典型相关的移动。如果谷歌生产规范ID为现有的登记,并将其传递回应用程序后端,它也将改变移动的注册ID,如果它调用注册方法?是否有移动任何其他方式去得到有关这个新的ID?

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?

非常感谢你提前!

推荐答案

谷歌建议,在安装了新版本之后推出的应用程序您的应用程序应该无效的注册ID。他们的<一个href=\"http://$c$c.google.com/p/gcm/source/browse/gcm-client/GcmClient/src/main/java/com/google/android/gcm/demo/app/DemoActivity.java\"相对=nofollow> GCM演示应用实现了这个建议。除了这种情况下,就没有必要再调用寄存器方法不止一次(当应用程式第一发射)。

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).

至于注销 - 他们建议注销如果你想改变你的发送者ID,或者在自己的服务器注册失败。究其原因,后者则是,如果你的服务器从来没有从你的应用程序的注册ID,它不会使用该注册的ID,所以没有理由为应用程序注册到GCM(除非你的应用程序会稍后重试发送注册ID到您的服务器)。

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被返回到我的服务器的唯一方式是通过注销从GCM应用程序(无效旧的注册ID),然后重新注册以获得新注册ID。在这种情况下,如果服务器使用旧的注册ID,它会工作,但新注册ID将返回为规范注册ID。这是主要的原因建议不要进行不必要的注销(以避免产生多个注册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(是,寄存器将返回最新的注册ID,这是相同的规范注册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.

您可以阅读更多的<一个href=\"http://stackoverflow.com/questions/16838654/handling-registration-id-changes-in-google-cloud-messaging-on-android/\">here有关处理注册ID的变化和<一个href=\"http://stackoverflow.com/questions/12808959/canonical-registration-id-and-message-id-format/\">here关于规范注册ID。

You can read more here about handling registration ID changes and here about canonical registration ID.

这篇关于谷歌云消息 - 注册ID状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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