两个不同的设备是否可以具有相同的 GCM 注册 ID? [英] Can two different devices have same GCM Registration ID?

查看:28
本文介绍了两个不同的设备是否可以具有相同的 GCM 注册 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为我的 Android 应用程序开发 GCM.我注意到几乎每次我的设备都有不同的 GCM 注册 ID.对 GCM 注册 ID 保持 UNIQUE_KEY 约束是否安全?并删除所有出现错误 NotRegistered 的 ID 并更新所有 canonical_ids?

I have been working on GCM for my Android app for a bit. I have noticed that almost every time I have a different GCM Registration ID for my device. Is it safe for me to keep a UNIQUE_KEY constrain on GCM Registration ID? And delete all the IDs with the error NotRegistered and update all the IDs which are canonical_ids?

推荐答案

注册 ID 与在特定设备上运行的特定 Android 应用程序相关联.

a registration ID is tied to a particular Android application running on a particular device.

(来自 GCM 概览)

两个不同的设备总是有不同的注册 ID.即使同一设备上的不同应用程序也有不同的注册 ID.

Two different devices would always have a different registration id. Even different apps on the same device have different registration ids.

在注册 ID 上保留 UNIQUE_KEY 约束在功能上是安全的,但由于注册 ID 可能很长(最多 4096 字节,但实际上通常更短),某些数据库可能会阻止您定义索引或限制在这么大的列上.您可能希望使用单向哈希函数将注册 ID 映射到较小的值,将该值存储在较小的列中,并在该列上设置约束/索引.

Functionally it is safe to keep a UNIQUE_KEY constraint on the Registration ID, but since the Registration ID can be long (up to 4096 bytes, though in practice it's usually much shorter), some databases may prevent you from defining an index or constraint on such a large column. You might want to use a one way hash function that would map the Registration ID to a smaller value, store that value in a smaller column and have the constraint/index on that column.

当您收到 NotRegistered 错误时,您确实应该从数据库中删除该注册 ID(或至少将其标记为非活动状态,并停止向其发送消息).但是,如果该应用程序将重新安装在之前卸载它的设备上,则该应用程序在再次注册到 GCM 时可能会获得相同的注册 ID,因此您的服务器应该允许注册 ID 曾经给 NotRegistered 重新激活.

When you get NotRegistered error, you should indeed delete that registration ID from your DB (or at least mark it with a status that says it is inactive, and stop sending messages to it). But if the app will be re-installed on a device from which it was earlier uninstalled, the app may get the same registration ID when it registers again to GCM, so your server should allow registration IDs that at one point gave NotRegistered to become active again.

当您在 Google 的响应中获得规范的注册 ID 时,您应该更新旧的注册 ID.

You should update the old registration ID when you get canonical registration ID in the response from Google.

这篇关于两个不同的设备是否可以具有相同的 GCM 注册 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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