XAMARIN Android - 应用内通知在 Xamarin.Firebase.Messaging 的 RELEASE 模式下不起作用

问题描述 投票:0回答:2

我有一个带有 Xamarin 的 Android 应用程序,我使用 FirebaseMessaging 来接收通知。当应用程序关闭时我会收到通知,当应用程序打开时我会在应用程序中收到通知。

当我的应用程序在 DEBUG 模式下运行一切正常,我收到通知很好。

但是,当我的应用程序以RELEASE模式运行时,或者如果我使用我的应用程序的APK应用程序中的通知不再有效......但是如果应用程序关闭它们仍然有效。

这里是*获取令牌*的代码:

     public string GetToken()
        {
            string token = CrossFirebasePushNotification.Current.Token;
          
            return token;
        }

这里的代码*在应用程序运行时接收通知: *

[Service(Exported = false)]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class FirebaseService : FirebaseMessagingService
    {

        public override void OnMessageReceived(RemoteMessage message)
        {
            //Log.Debug(TAG, "Venant de: " + message.From);
            //Log.Debug(TAG, "Contenu de la notif: " + message.GetNotification().Body);

            if (message.GetNotification() != null)
            {
                long longDate = message.SentTime;
                DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                DateTime dateTimeNotif = start.AddMilliseconds(longDate).ToLocalTime();

                EventCatch newNotif = new EventCatch
                {
                    Id_Client = AccesData.clientCourant.Id_Client,
                    Id_Compte = AccesData.compteCourant.Id_Compte,
                    NotifTitle = message.GetNotification().Title,
                    NotifBody = message.GetNotification().Body,
                    Lu = false,
                    NotifDateHeureEnvoi = dateTimeNotif,
                };

                AccesData accesData = new AccesData();
                accesData.SauvEventLocal(newNotif);

                accesData.OnNewEvent(newNotif);
            }
        }
}

这里的事件代码捕获通知的主体当应用程序正在运行时,并将其显示给用户:

  public void OnNewEvent(EventCatch eventCatch)
        {
            RecupNotif?.Invoke(eventCatch, EventArgs.Empty);
        }

还有 delegate,在我的 XAML 页面的代码后面:

 AccesData.RecupNotif += ShowNewNotification;

*功能*(收到通知时,我在导航栏中有一个变红的铃铛):

  private void ShowNewNotification(object sender, EventArgs e)
        {
            //frameNotif.IsVisible = true;
            btnAlertNotif.BackgroundColor = Color.Red;
        }

DEBUG MODE中,一切正常,我收到所有通知,在应用程序中,以及应用程序关闭时。

但是在RELEASE模式中,只有应用内通知不起作用,使用APK,或者在PRODUCTION...

我不明白为什么?我已经坚持了一个多月了。

看来这个悬而未决的问题和我的问题类似

任何想法?感谢您的帮助。

android xamarin.android notifications
2个回答
0
投票

您的 google-services json 是否为您的发布版本包含额外的 SHA 证书指纹?


0
投票

您可以先重新检查您是否已将用于发布的 SHA-1 签名密钥添加到您的 firebase 控制台。

对于发布版本,有一个不同的 SHA-1 密钥。

您可以尝试以下步骤:

  • 生成您的
    SHA-1
    以供发布
  • 将您的版本
    SHA-1
    添加到 firebase 控制台
  • 下载并使用新的
    google-services.json
    .

注意: 确保 Play 商店用于签署您的版本的密钥是 也在步骤 2

中添加

关于这个问题有一些类似的帖子,你可以在这里查看:

FCM 通知在发布应用程序中不起作用

Firebase 谷歌身份验证在发布模式下不起作用

© www.soinside.com 2019 - 2024. All rights reserved.