GCM"注册ID"已不再注册

Tal*_* Sh 6 android google-cloud-messaging

我按照Google GcmClient应用程序中给出的步骤生成了存储在我的SharedPrefs中的registrationId.这样,只有在更改appVersion时才会重新生成register-id.

此reg-id被发送到我的服务器(基于Rails),并通过GCM gem(https://github.com/spacialdb/gcm)将通知发送到Android设备.

问题:有时服务器收到"未注册"的响应,尽管相同的register-id在失败前几分钟就已经工作了.

当发生这种情况时,我试图"清除数据"并且新生成的reg-id与最后一个不同... 注册ID可能在没有更新应用程序的情况下过期(当然我没有调用注销)?

我阅读了类似问题的帖子并谷歌但仍无法确定所有这些失败的常见现象.当我从GoogleStore(生产中)下载应用程序而不更新应用程序时,也出现了此问题.

注册到GCM的主要方法:

public static void register(Context context, IGcmRegisterationListener listener) {
    try {
        MyLog.v("GcmClient: Registering for GCM...");
        Context appContext = context.getApplicationContext();
        // Check device for Play Services APK. If check succeeds, proceed with
        //  GCM registration.
        if (checkPlayServices(appContext)) {
            MyLog.v("GcmClient: Looking for GCM regId locally");
            String currentRegId = getRegistrationIdFromPrefs(appContext);

            if (currentRegId == null) {
                MyLog.v("GcmClient: GCM regId not found.");
                registerInBackground(appContext, listener);
            }
            else {
                MyLog.v("GcmClient: GCM regId found: " + currentRegId);
                listener.onGcmRegistered(context, currentRegId);
            }
        } else {
            MyLog.i("GcmClient: No valid Google Play Services APK found.");
            listener.onGcmRegistrationFailed();
        }
    } catch (Exception ex) {
        MyLog.i("GcmClient: GCM registration failed: " + Log.getStackTraceString(ex));
        listener.onGcmRegistrationFailed();
    }
}
Run Code Online (Sandbox Code Playgroud)