如果应用程序调用gcm.register()每七天,以确保有效的注册证书? [英] Should applications call gcm.register() every seven days to ensure valid registration IDs?

查看:124
本文介绍了如果应用程序调用gcm.register()每七天,以确保有效的注册证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android开发的客户端code在 GCM例子网站默认调用 gcm.register(SENDER_ID); 每七天使用以下功能检查,如果注册有效期届满后:

 公共静态最后长REGISTRATION_EXPIRY_TIME_MS = 1000 * 3600 * 24 * 7;

/ **
 *检查是否登记已过期。
 *
 *若要避免设备发送注册的场景
 *服务器,但服务器失去它,应用程序开发者可以选择重新注册
 * REGISTRATION_EXPIRY_TIME_MS后。
 *
 * @返回true,如果登记已过期。
 * /
私人布尔isRegistrationExpired(){
    最终的共享preferences preFS = getGCM preferences(上下文);
    //检查是否信息不陈旧
    长expirationTime =
            prefs.getLong(PROPERTY_ON_SERVER_EXPIRATION_TIME,-1);
    返回的System.currentTimeMillis()> expirationTime;
}
 

上述功能的注释意味着这是用来避免其中设备发送注册到服务器的情况下,但在服务器失去它。这是暗示的我们的的服务器(不是GCM服务器)可能会失去的注册ID?或者这是因为注册ID可能会成为物联网的GCM侧无效?看来,这是可能的,每个在的的GCM高级主题Page

  

同样,你不应该当一个应用程序保存注册ID   备份。这是因为的注册ID可能会变得无效   由当时的应用程序恢复,它会把   处于无效状态的应用程序(即,应用程序认为它是   注册,但服务器和CM不存储的注册ID   再 -thus的应用程序不会得到更多的消息)。

感谢你在前进!

解决方案
  1. 您说:

      

    上述功能的注释意味着这是用来避免场景的设备发送   注册到服务器,但在服务器失去它。这是   这表明我们的服务器(而不是GCM服务器)可能会失去   注册ID?或者,这是因为注册ID有可能成为   对事物的GCM侧无效?

    我觉得他们是在谈论我们的服务器(第三方服务器) 和NOT GCM服务器。第二点,将清除多一点。

  2. 另外,你提到的文档说:

      

    您不应该保存注册ID当应用程序进行备份。这是   因为注册ID可能成为由时间无效的   应用被恢复,这将使该应用程序中的   无效状态。

    我想如果你仔细阅读标题下的第二个点 启用GCM 结构概述页面,它说:

      

    请注意,谷歌可能会定期刷新注册ID,所以   你应该设计自己的Andr​​oid应用程序的理解   该 com.google.android.c2dm.intent.REGISTRATION 的意图可能是   多次调用。 Android应用程序需要能够   作出相应的反应。

    所以,谷歌可能会定期刷新自己注册ID的。这就是为什么 注册ID可能成为由当时的应用是无效 恢复。

    所以,处理,你应该有一个广播监听器,可以处理 com.google.android.c2dm.intent.REGISTRATION 的意图,这谷歌发送到应用程序时它具有以刷新注册ID。

    这也可以清楚的第一点。由于这种情况下处理来自谷歌方面的ID清爽,当地7天有效期将处理失去第三部分服务器上的ID(因为它是被每7天以后定期刷新)的其他情况。

这是我的看法对你的问题。希望这可以帮助。

The client-side code in the GCM example on the Android dev site defaults to calling gcm.register(SENDER_ID); after every seven days by checking if registration has expired using the following function:

public static final long REGISTRATION_EXPIRY_TIME_MS = 1000 * 3600 * 24 * 7;

/**
 * Checks if the registration has expired.
 *
 * To avoid the scenario where the device sends the registration to the
 * server but the server loses it, the app developer may choose to re-register
 * after REGISTRATION_EXPIRY_TIME_MS.
 *
 * @return true if the registration has expired.
 */
private boolean isRegistrationExpired() {
    final SharedPreferences prefs = getGCMPreferences(context);
    // checks if the information is not stale
    long expirationTime =
            prefs.getLong(PROPERTY_ON_SERVER_EXPIRATION_TIME, -1);
    return System.currentTimeMillis() > expirationTime;
}

The comment above the function implies that this is used to "avoid the scenario where the device sends the registration to the server but the server loses it. Is this suggesting that our servers (not the GCM servers) may lose the registration id? Or is this because the registration ID could become invalid on the GCM side of things? It appears that this is possible as per the following paragraph in the GCM Advanced Topics Page:

Similarly, you should not save the registration ID when an application is backed up. This is because the registration ID could become invalid by the time the application is restored, which would put the application in an invalid state (that is, the application thinks it is registered, but the server and CM do not store that registration ID anymore—thus the application will not get more messages).

Thank you in advance!

解决方案

  1. You said:

    The comment above the function implies that this is used to "avoid the scenario where the device sends the registration to the server but the server loses it. Is this suggesting that our servers (not the GCM servers) may lose the registration id? Or is this because the registration ID could become invalid on the GCM side of things?

    I think they are talking about our servers( the 3rd party servers) and NOT GCM servers. The second point will clear that a bit more.

  2. Also, you mentioned that the docs say:

    You should not save the registration ID when an application is backed up. This is because the registration ID could become invalid by the time the application is restored, which would put the application in an invalid state.

    I think If you carefully read the second point under the heading Enable GCM on Architectural Overview page, it says:

    Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.

    So, Google may refresh he registration ID's periodically. That's why registration ID could become invalid by the time the application is restored.

    So, for handling that you should have a Broadcast Listener which could handle com.google.android.c2dm.intent.REGISTRATION intent, which Google send to the app when it has to refresh the registration ID.

    This also might clear the first point. As this case is handling the refreshing of the ID from Google side, the local 7 days validity will handle the other case of loosing the ID on 3rd part server( as it is being refreshed periodically after every 7 days).

This is my view about your question. Hope this helps.

这篇关于如果应用程序调用gcm.register()每七天,以确保有效的注册证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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