【问题标题】:Do I need to handle app updates in iOS for Google Cloud Messaging?我是否需要在 iOS 中为 Google Cloud Messaging 处理应用更新?
【发布时间】:2016-07-07 18:45:45
【问题描述】:

我们在表单应用中使用 Google Cloud Messaging。在 Android 端,当我们进行更新时,该应用程序未注册。我们无法保证用户在更新后会打开我们的应用,所以我们需要处理这种情况。

我无法确定这是否会成为 iOS 的问题。有谁知道 GCM 是否可以更好地处理 iOS 上的更新/替换应用程序并且我们不需要额外的代码?

【问题讨论】:

    标签: ios xamarin xamarin.ios google-cloud-messaging


    【解决方案1】:

    Keeping the Registration State in Sync中所述:

    为了保护客户端应用程序和应用程序服务器免受潜在的恶意注册令牌的重复使用,您应该定期从服务器启动令牌刷新。当从服务器端启动 GCM 注册令牌刷新时,客户端应用必须通过 GCM 注册客户端/服务器握手处理 tokenRefreshed 消息

    对于 iOS,Handle refreshed tokens 中声明:

    为了处理注册令牌已被刷新的情况,GGLInstanceIDDelegate 协议声明了一个onTokenRefresh 方法,当系统确定需要刷新令牌时调用该方法。

    示例代码:

    - (void)onTokenRefresh {
      // A rotation of the registration tokens is happening, so the app needs to request a new token.
      NSLog(@"The GCM registration token needs to be changed.");
      [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:_gcmSenderID
                                                          scope:kGGLInstanceIDScopeGCM
                                                        options:_registrationOptions
                                                        handler:_registrationHandler];
    }
    AppDelegate.m
    

    此外,为了处理令牌刷新,客户端应用程序应该:

    1. 声明一个采用GGLInstanceIDDelegate协议的类;
    2. 使用委托属性将该类设置为GGLInstanceIDConfig 上的委托。

    您可以在给定的文档中找到可以提供帮助的其他参考资料。

    除此之外,这篇 SO 帖子 - Why re-register to gcm when application gets updated 还解释了为什么需要刷新令牌。

    【讨论】:

    • 感谢您的回答。请帮助我理解:更新应用程序时是否会触发 onTokenRefresh?还是您建议从服务器端发出的定期刷新会缓解这种情况?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多