【问题标题】:InstanceID.GetToken returns incorrect token after Android app updateAndroid 应用更新后 InstanceID.GetToken 返回不正确的令牌
【发布时间】:2016-08-17 17:35:19
【问题描述】:

我有一个应用程序,当您安装它时,它可以很好地接收通知。更新一次或多次后,无法再收到通知。更新应用程序后,它会继续重新发出我第一次安装应用程序时获得的相同令牌,但是当我检查来自 GCM REST API 的错误消息时,它此时显示“未注册”。

这是一个 Xamarin Native Android 应用。

谁能向我解释我做错了什么?

【问题讨论】:

  • 此行为是否发生在已发布的应用程序中,还是调试版本?
  • 这是一个调试版本
  • 是这样想的。希望答案中的代码对您有所帮助。似乎是相同的行为。

标签: android xamarin notifications push


【解决方案1】:

我们在 Xamarin Forms 应用程序中遇到了同样的行为,但由于通知注册过程是特定于平台的,这可能对您的情况也有帮助。

在注册通知OnHandleIntent 方法的 Xamarin Droid 服务类中,我们删除先前的 GCM 实例 id 并在每次运行调试构建时请求一个新的:

    protected override void OnHandleIntent(Intent intent)
    {
        try
        {
            Log.Info("NotificationRegistrationIntentService", "Calling InstanceID.GetToken");
            lock (Locker)
            {
                var instanceId = InstanceID.GetInstance(this);
#if DEBUG
                // Ensure a fresh instance id for debug builds.
                instanceId.DeleteInstanceID();
                instanceId = InstanceID.GetInstance(this);
#endif
                var token = instanceId.GetToken(SenderId, GoogleCloudMessaging.InstanceIdScope, null);

【讨论】:

  • 谢谢马克,这很有趣!我要试试这个。
猜你喜欢
  • 2017-10-07
  • 2017-05-16
  • 2021-09-28
  • 2013-05-10
  • 2019-10-10
  • 1970-01-01
  • 2014-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多