【问题标题】:Xamarin iOS firebase issueXamarin iOS firebase 问题
【发布时间】:2017-10-17 12:16:01
【问题描述】:

作为我项目的一部分,我正在为 iOS 开发 Firebase 云消息传递。我的部分问题如下:iOS 应用的 AppDelegate 包含以下代码:

        // Monitor token generation
        InstanceId.Notifications.ObserveTokenRefresh((sender, e) =>
        {
            // Note that this callback will be fired everytime a new token is generated, including the first
            // time. So if you need to retrieve the token as soon as it is available this is where that
            // should be done.
            var refreshedToken = InstanceId.SharedInstance.Token;
            Console.WriteLine(refreshedToken);

            if (refreshedToken != null)
            {
                if (credentialsService.Email.Equals("") && credentialsService.Password.Equals(""))
                {
                    credentialsService.SaveCredentials(refreshedToken);
                }
                else
                {
                    credentialsService.SaveCredentials(credentialsService.Email, credentialsService.Password, refreshedToken, credentialsService.Token);
                }
            }
            else
            {
                Console.WriteLine("error, token is empty");
            }
        });

只要需要令牌,就会调用此回调函数。然后,credentialsService 将用于收集该令牌并在用户登录时将其发送到服务器。但是,问题是该令牌没有立即准备好。在加载此应用程序的启动屏幕之前,将为其 android 版本(工作方式几乎相同)分配一个令牌。然而,iOS 应用程序在生成令牌之前需要大量时间(大约 20-30 秒)。用户此时已经可以登录,之后生成的任何令牌都只会在用户重新登录后发送到服务器。

是否有任何解决方案可以确保更快地生成令牌?我确实收到以下错误,这在互联网上并不少见。然而,在谷歌上搜索解决方案并没有真正的帮助。

无法获取 APNS 令牌错误 Domain=com.firebase.iid Code=1001 "(null)"

FIRMessaging 注册尚未准备好使用身份验证凭据

谢谢你, 里卡多

【问题讨论】:

  • 同样的问题有人帮忙吗?..

标签: ios firebase xamarin firebase-cloud-messaging


【解决方案1】:

我有一个解决方案,但很丑:

            while (string.IsNullOrEmpty(token))
        {
            _taskToken.Wait(1000);
            this.token = InstanceId.SharedInstance.Token;
        }

你可以等待 60 或 90 秒后刷新,然后获取令牌..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-25
    • 2019-04-30
    • 2016-06-16
    • 2020-10-24
    • 2020-12-21
    • 2018-02-27
    • 2022-10-20
    • 2020-06-26
    相关资源
    最近更新 更多