当用户在Xamarin Forms应用程序中点击“本地通知"时,如何导航到特定页面? [英] How to navigate to a particular page when user taps on a Local Notification in Xamarin Forms app?

查看:150
本文介绍了当用户在Xamarin Forms应用程序中点击“本地通知"时,如何导航到特定页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在开发Xamarin Forms应用程序.我已经在应用程序中实现了本地通知.触发通知后,单击通知后,它必须导航到特定页面. 在Appdelegate.cs的iOS项目中,我编写了此方法

Hi am developing a Xamarin Forms app. i have implemented local notifications in the app. When the notification has fired, upon clicking the notification it has to navigate to a particular page. In iOS project in Appdelegate.cs i wrote this method

    public async  override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)

,当用户点击通知时,它将触发.在这里,我需要导航到页面.在这里,我写了下面的代码行

which will fire when the user taps on the notification. here i need to navigate to a page. Here i wrote the below line of code

            App.Current.MainPage  = new NavigationPage(new FavoritesPage());

它正在导航到收藏夹"页面,但仅显示空白页面. OnNavigatedTo方法不调用收藏夹视图模型,并且在Onnavigated中调用一个将id(此id来自通知)作为参数以获取特定收藏夹的方法 这里有两个问题 1)如何导航到特定页面 2)如何将参数与页面导航一起传递. 有人可以帮我解决这个问题.

It is navigating to the Favorites page but it is just displaying a blank page. OnNavigatedTo method is not calling for the FavoritesViewModel and in the Onnavigated to am calling a method which takes id(this id comes from the notification) as parameter to get a particular favorite Here two questions 1) How to navigate to a Specific page 2) How to pass a parameter along with the page navigation. Can someone please help me to solve this issue.

推荐答案

对于1:

您想推送到新页面,但是您要做的是替换应用程序的MainPage.请尝试PushAsync.您可以在App中订阅MessagingCenter:

For 1:

You want to push to a new Page, but what you did is replacing the app's MainPage. please try PushAsync. You can subscribe a MessagingCenter in App:

public App ()
{
    InitializeComponent();

    MainPage = new NavigationPage(new MainPage());

    MessagingCenter.Subscribe<object, string>(this, "Push", async (sender, favoriteID) =>
    {
        var favorite = new FavoritesPage();
        favorite.FavoriteID = favoriteID;
        await (MainPage as NavigationPage).PushAsync(favorite, true);
    });
}

当您致电MessagingCenter.Send<object, string>(this, "Push", "01");时,此Lambda会触发 字符串 01 是我要推送的ID.

This Lambda will fire when you call MessagingCenter.Send<object, string>(this, "Push", "01"); The string 01 here is the ID what I want to push.

在我进入新页面之前,先在此页面中定义一个名为FavoriteID的属性,然后使用上述方法传递字符串.

Before I push to a new page, I define a property called FavoriteID in this page, then I pass the string using method above.

这篇关于当用户在Xamarin Forms应用程序中点击“本地通知"时,如何导航到特定页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆