gcm 规范 ID 是否应该更新 [英] gcm canonical id should be updated or not

查看:21
本文介绍了gcm 规范 ID 是否应该更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 gcm 的 android 项目.我开始知道如果我们从设备上卸载应用程序并重新安装大部分时间设备会获得新的注册 ID.然后如果我们不从应用程序服务器中删除旧的并更新,消息将发送到两个 ID 和响应它将显示规范 ID 存在.我的问题是,此时消息是否会成功发送到该设备?

I am working on an android project which uses gcm. I came to know that if we uninstall the appfrom device and reinstalled most of the time the device gets new registration id.Then if we do not delete the old one from application server and update, The messages will be sending to both ids and in the response it will be showing canonical id is present.My question is, at this point message will be successfully send to that device or not?

推荐答案

当您在 Google 的响应中收到规范的注册 ID 时,该消息已被 GCM 服务器接受并且 GCM 服务器将尝试将其传送到设备.是否实际发送到设备取决于设备是否可用(即连接到互联网).因此,如果您的服务器向旧 ID 和新 ID 都发送 GCM 消息,则设备可能会收到两条消息.

When you receive a canonical registration ID in the response from Google, the message was accepted by the GCM server and the GCM server would attempt to deliver it to the device. Whether it is actually sent to the device depends on whether the device is available (i.e. connected to the internet). So if your server sends a GCM message to both the old ID and the new ID, the device will probably get two messages.

规范 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.

(来源)

您可以通过为应用程序的每个实例分配一个唯一标识符来解决这个问题.如果您将该标识符存储在设备的外部存储中,则卸载应用程序时不会删除该标识符.然后您可以在再次安装该应用程序时恢复它.如果您将此标识符与注册 ID 一起发送到您的服务器,您可以检查您的服务器是否有此标识符的旧注册 ID,然后将其删除.

You can overcome this problem by assigning a unique identifier to each instance of your application. If you store that identifier in the device's external storage, it won't be deleted when the app is uninstalled. Then you can recover it when the app is installed again. If you send this identifier to your server along with the registration ID, you can check if your server has an old registration ID for this identifier, and delete it.

这篇关于gcm 规范 ID 是否应该更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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