【问题标题】:How to use both Firebase Cloud Messaging and Firebase Auth in Xamarin?如何在 Xamarin 中同时使用 Firebase Cloud Messaging 和 Firebase Auth?
【发布时间】:2020-07-05 05:41:21
【问题描述】:

我正在开发 Xamarin Android 原生应用,但在尝试同时使用 FCM 和 Firebase-Authentication 时遇到问题。

我首先将 FCM 包添加到我的应用程序(最新版本 v71.1740),我使用 FirebaseMessagingService 和 google-services.json 并且它运行良好,每次新安装都会触发 OnNewToken 方法。

然后我添加了 Firebase-Authentication Nuget 包 (v71.16),而没有修改我的代码中的任何内容。我卸载了应用程序并重新启动,但我从未收到任何推送令牌。

如果我删除 Auth 包,则会触发 OnNewToken 方法。

用这两个模块初始化 Firebase 有什么办法,还是 Xamarin 错误? 谢谢

【问题讨论】:

  • 我自己对此相当陌生,但是当您启用身份验证功能时,您是否更新了您的 google-services Json / PList?我在组合服务时遇到了类似的问题,并且由于添加了一些密钥而不得不下载新配置。
  • 是的,我做到了,但没有成功。我还尝试创建一个新的空白项目来检索推送令牌。它工作正常,但如果我添加 Firebase-Authentication 包:同样的问题,根本没有令牌。对我来说,这似乎是一个卷轴错误。

标签: android firebase xamarin firebase-authentication firebase-cloud-messaging


【解决方案1】:

在我的项目中,我意识到 OnNewToken 断点不会触发,但令牌会正常更新。我知道这一点是因为 LOG 显示给我看。这是我的代码:

namespace MyApp
{
   [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class MyFirebaseMessagingService : FirebaseMessagingService
    {
        const string TAG = "Firebase";

        public override void OnNewToken(string token)
        {
            base.OnNewToken(token);

            Log.Debug(TAG, "Update Token: " + token);

            Preferences.Set("TokenFirebase", token);            
        }

        public override void OnMessageReceived(RemoteMessage message)
        {
            
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-25
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    相关资源
    最近更新 更多