如果Xamarin.Forms iOS和Android被终止,则在收到通知后收到通知会运行什么代码?

问题描述

我正在使用One Signal在Xamarin Forms中实现推送通知。我想在应用程序被杀死时接收推送通知,并通过使用随通知有效负载返回的键/值对来执行一些代码

 HandleNotificationReceived((args)=>
         {
            Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
            {
                Dictionary<string,object> additionalData = args.payload.additionalData;
                string code = "";
                //if(args.payload.additionalData.Count > 0)
                //{
                //    if(additionalData.ContainsKey("code"))
                //    {
                //        var obj = (string)additionalData["code"] ;

                //    }
                //}
                //code = "raya12";

                NotificationModel notification = new NotificationModel { Title = args.payload.title,Description = args.payload.body,ShortDescription = args.payload.subtitle };
                var oldList = Kun.Helpers.Settings.Notifications;
                oldList.Add(notification);
                Kun.Helpers.Settings.Notifications = oldList;

                // update count Now
                if (Settings.mainPage != null && Settings.mainPage.ALNavigation != null
                && Kun.Helpers.Settings.Notifications != null && Settings.notificationsScreen != null
                && Settings.notificationsScreen.Notifications != null)
                {
                    Settings.mainPage.ALNavigation.NotificationsCount = Kun.Helpers.Settings.Notifications.Count;
                    Settings.notificationsScreen.Notifications = Kun.Helpers.Settings.Notifications;
                    Settings.notificationsScreen.RefreshList();
                }
            });
        }).
        HandleNotificationopened(async(args)=>
        {
            OSNotificationopenedResult result = args;
            if (Settings.courseDetailsScreen != null)
            {
                await Settings.courseDetailsScreen.CourseClickAsync("raya12");
            }
        })
        .EndInit();

这就是我现在在共享项目中处理通知的方式。

解决方法

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

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

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