GCM 注册 ID 会过期吗? [英] Do GCM registration id's expire?

查看:36
本文介绍了GCM 注册 ID 会过期吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 C2DM 注册会过期,您应该定期刷新注册 ID.GCM 是这种情况吗?通过查看Android GCM指南(如下所示)上的以下代码,您似乎只执行一次并且不需要刷新,但是我没有在任何地方看到明确写过,所以我只是想检查一下.

I know that C2DM registrations expire, and you are supposed to periodically refresh the registration ID. Is this the case with GCM? by looking at the following code on the Android GCM guide (shown below), it seems like you only do it once and don't need to refresh, but I dont see that explicitly written anywhere, so I just wanted to check.

final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
  GCMRegistrar.register(this, SENDER_ID);
} else {
  Log.v(TAG, "Already registered");
}

推荐答案

这个答案已经过时了,我不知道当前的行为是什么

我自己找到了答案.您不必一直明确地重新注册,只需根据到文档中的示例.

I found the answer myself. You don't explicitly need to re-register all the time, just once according to the example in the docs.

此外,与以前版本的 GCM 和 C2DM 不同,Google 本身不会现在刷新注册本身:一旦您获得了初始注册的注册 ID,您就可以了去,除了一种情况:当用户升级到新版本时,您仍然需要重新注册(这种情况也在上面链接中的示例中处理):

Also, unlike previous versions of GCM and C2DM, Google itself does not refresh the registration itself now: once you have the registration id from the initial registration you are good to go, except for one case: you do still need to re-register when the user upgrades to a new version (this case is also handled in the example in the link above):

当应用程序更新时,它应该使其现有的无效注册 ID,因为它不能保证与新版本一起使用.因为在应用程序启动时没有调用生命周期方法更新,实现此验证的最佳方法是存储存储注册 ID 时的当前应用程序版本.

When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version. Because there is no lifecycle method called when the application is updated, the best way to achieve this validation is by storing the current application version when a registration ID is stored.

这篇关于GCM 注册 ID 会过期吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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