我在我的应用程序中使用 gcm。 在Google Developers Console页面中,我创建了一个项目并获取了项目id:
在我的应用程序中使用此项目 ID,用户可以注册到 gcm 服务器并获得注册 ID。然后它被发送到我的第 3 方服务器进行存储。
当第 3 方服务器想要向用户发送消息时,它会使用我在 post 操作标题中的 Google 开发者控制台页面中获得的 apikey,并使用为此特定用户存储的注册 ID。我使用的 api key 来自:
请注意,这是服务器应用程序的关键,我使用此信息的方式正如我所解释的那样。
一切正常,消息由正确的用户检索等等。我计划在 Google Play 上部署我的应用程序,但本节中写的是:GCM advanced topics让我困惑。它说:
When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version
以及Implementing GCM client sample code中示例代码的注释部分有这样一条评论:
// Check if app was updated; if so, it must clear the registration ID
// since the existing regID is not guaranteed to work with the new
// app version.
这两种解释是什么意思?我想除非我在这里按重新生成键:
我的 api key 不会改变。当我更新我的应用程序时,为什么它应该(或者确实)发生变化?还是我弄错了什么?
最佳答案
您正在混合使用两个不同的术语 - API key 和注册 ID。部署新版本时,您不必创建新的 API key 。
Google 建议(在上面引用的内容中)将安装新版本的每台设备重新注册到 GCM(而不是依赖之前获得的注册 ID),因为分配给 GCM 的现有注册 ID不保证您的应用程序的设备适用于新版本的应用程序。
关于android - 为什么应用程序更新后要重新注册到 gcm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21741183/