使用 FirebasePushNotificationPlugin 插件和 Autofac 和 Shell 的 Xamarin Forms 无法显示 UI 元素或重定向

问题描述

我遇到了一个问题,我尝试了不同的方法解决,但都没有成功。每当通过 CrossFirebasePushNotification.Current.OnNotificationReceived 接收消息时,我都会获取有效负载并可以读取它,但我无法在我的应用程序中执行任何“可视化”操作。换句话说,我收到了通知,但是当我想重定向到另一个页面甚至显示 displayAlert 消息时,什么也没有发生。可以接收 MessagingCenter,但过程中与重定向displayAlert(任何改变它出现的 UI)有关的任何指令都不会执行。 寻求有关如何在应用中直观地显示用户收到的消息的帮助。

这是在 MainShell.xaml.cs 中(我也将它放在 App.xaml.cs 中):

CrossFirebasePushNotification.Current.OnNotificationReceived += (s,p) =>

{

        System.Diagnostics.Debug.WriteLine("Received");  // this works
        foreach (var data in p.Data)
        {
            System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}"); // this works
        }

        //Todo:  Code to determine if user is signed in
        if (true)
        {
            System.Diagnostics.Debug.WriteLine("Debug:  Goto Registration page from MainShell"); // this works
            //Task.Run(async () => await Shell.Current.GoToAsync("registration"));  // this does not work (just ignores it and doesn't fire constructor)                    
            //Task.Run(async () => await Current.displayAlert("Request Received","A message is waiting...","Ok"));  // this does not work
            MessagingCenter.Send(this,"RequestReceived"); // this works,the receiver will display debug info,but will not redirect nor display any UI messages or interact with the UI.

        }

    };

感谢您的任何帮助或指导,

罗伯特

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)