gpt4 book ai didi

Xamarin Forms - 如何在应用程序关闭时单击通知后打开特定页面?

转载 作者:行者123 更新时间:2023-12-03 22:16:23 26 4
gpt4 key购买 nike

我实际上正在开发一个需要推送通知的 Xamarin Forms 应用程序。我使用 Plugin.PushNotification 插件。

当应用程序在前台运行或处于 sleep 状态(OnSleep)时,当我点击收到的通知时打开特定页面没有问题。但我想知道当应用程序关闭时我该怎么做。谢谢!

最佳答案

我终于自己找到了答案,我想分享它以防有人需要它。

通知 :根据插件的官方文档,它是Xam.Plugin.PushNotification已弃用。我使用这个插件的新版本,Plugin.PushNotification它使用 FCM for Android 和 APS for iOS。

在应用程序运行、 sleep 或关闭时打开通知没有显着差异。只需在 中添加下一个回调方法即可创建 方法(MyProject.Droid > MainApplication > OnCreate)和完成上线方法(MyProject.iOS > AppDelegate > FinishedLaunching):

CrossPushNotification.Current.OnNotificationOpened += (s, p) =>
{
// manage your notification here with p.Data
App.NotifManager.ManageNotif(p.Data);
};

公用部分

应用程序.xaml.cs
// Static fields
// *************************************

public static NotifManager NotifManager;

// Constructor
// *************************************

public App()
{
...
NotifManager = new NotifManager();
...
}

通知管理器.cs
public class NotifManager
{
// Methods
// *************************************

public void ManageNotif(IDictionary<string, object> data)
{
// 1) switch between the different data[key] you have in your project and parse the data you need
// 2) pass data to the view with a MessagingCenter or an event
}
}

关于Xamarin Forms - 如何在应用程序关闭时单击通知后打开特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50388329/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com