Android的GCM和多个令牌 [英] Android GCM and multiple tokens

查看:238
本文介绍了Android的GCM和多个令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册的GCM与GoogleCloudMessaging.getInstance(上下文);并节约设备接收的令牌。然后将其发送给服务器和它与用户帐户相关联。如果我卸载我的应用程序而不退出,并重新安装,并与其他用户登录时,我收到了新的令牌,并将其发送给服务器。当推压被发送给第一个用户我看到他们,当我登录时第二个用户。

I register in GCM with GoogleCloudMessaging.getInstance(context); and save received token on device. Then send it to server and it's associated with user account. If I uninstall my app without logging out and install again and log in with another user, I receive new token and send it to server. And when pushes being send to first user I see them when I logged in with second user.

为什么GCM向我发送不同的令牌,我该怎么处理呢?

Why does GCM sends me different tokens and how can I handle this?

推荐答案

欢迎到重复的邮件的奇妙世界的谷歌云消息传递。当发生这种情况时, GCM 引擎使规范标识来解决这个问题。这可能会发生,因为你注册几个ID的同一设备,或者是因为 GCM 服务器没有拿到取消注册()打电话的时候,应用程序卸载。使用规范的标识将设置你的ID是你所做的最后一次注册。

Welcome to the marvelous world of duplicate messages from Google Cloud Messaging. When this happens, the GCM engine enables the Canonical IDs to solve it. This might happen because you registered with several IDs for the same device, or because the GCM server didn't get the unregister() call when the app was uninstalled. Using canonical IDs will set your ID to be the last registration you've made.

由于每 GCM参考这一点:

典型的ID

在服务器端,只要应用程序表现很好,一切都应该正常工作。但是,如果在应用程序中的错误触发多个登记为同一台设备,它可以是难以调和的状态,你可能最终与重复的消息。

On the server side, as long as the application is behaving well, everything should work normally. However, if a bug in the application triggers multiple registrations for the same device, it can be hard to reconcile state and you might end up with duplicate messages.

GCM提供了一个名为规范注册的ID来轻易地从这些情况中恢复设施。一个规范的注册ID被定义为您的应用程序所要求的最后注册的ID。这是将消息发送到设备时,服务器应使用的ID。

GCM provides a facility called "canonical registration IDs" to easily recover from these situations. A canonical registration ID is defined to be the ID of the last registration requested by your application. This is the ID that the server should use when sending messages to the device.

如果您稍后尝试使用不同的注册ID发送消息,GCM将处理该请求像往常一样,但它会在响应的registration_id领域的规范注册ID。请务必将储存在你的服务器,这个规范ID的注册ID,因为最终你使用会停止工作的ID。

If later on you try to send a message using a different registration ID, GCM will process the request as usual, but it will include the canonical registration ID in the registration_id field of the response. Make sure to replace the registration ID stored in your server with this canonical ID, as eventually the ID you're using will stop working.

这里更多信息

More info here.

也有关于如何procceed实际情况下,可能会有所帮助:

Also there is a practical case on how to procceed, it might be helpful:

这篇关于Android的GCM和多个令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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