微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 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 举报,一经查实,本站将立刻删除。