使用Xamarin表格-pcl v 2.3.4.267 -Plugin.FirebasePushNotification v 1.04-和prism MVVM库 - 在Android设备上调试。
我根据此文档https://github.com/CrossGeeks/FirebasePushNotificationPlugin/blob/master/README.md实施了FCM 并且我已成功向应用程序发送通知,我所坚持的是
如何在用户点击通知时打开特定页面,并根据通知类型打开所选页面,例如(当用户点击接受优惠的通知时,将打开优惠页面,当用户点击警报通知时,警报页面将被打开。)
我尝试在App.cs类中实现IPushNotificationHandler但是onopened方法永远不会被命中。
除非OnNotificationOpened打开通知,否则从未打过电话。
更新
在App.cs中我订阅了一个主题
public App(Prism.DryIoc.IPlatformInitializer initializer = null) : base(initializer)
{
CrossFirebasePushNotification.Current.Subscribe("general");
CrossFirebasePushNotification.Current.OnTokenRefresh += (s,p) =>
{
System.Diagnostics.Debug.WriteLine($"TOKEN : {p.Token}");
};
CrossFirebasePushNotification.Current.OnNotificationReceived += (s,p) =>
{
System.Diagnostics.Debug.WriteLine("Received");
};
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
// System.Diagnostics.Debug.WriteLine("Opened");
foreach (var data in p.Data)
{
System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
}
if (!string.IsNullOrEmpty(p.Identifier))
{
System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
}
};
在mainapplication中,我添加了
#if DEBUG
FirebasePushNotificationManager.Initialize(this,
new NotificationUserCategory[]
{
new NotificationUserCategory("message",new List<NotificationUserAction> {
new NotificationUserAction("Reply","Reply", NotificationActionType.Default),
new NotificationUserAction("Forward","Forward", NotificationActionType.Foreground)
}),
new NotificationUserCategory("request",new List<NotificationUserAction> {
new NotificationUserAction("Accept","Accept", NotificationActionType.Default, "check"),
new NotificationUserAction("Reject","Reject", NotificationActionType.Default, "cancel")
})
}, true);
#else
FirebasePushNotificationManager.Initialize(this,
new NotificationUserCategory[]
{
new NotificationUserCategory("message",new
List<NotificationUserAction> {
new NotificationUserAction("Reply","Reply",
NotificationActionType.Foreground),
new NotificationUserAction("Forward","Forward",
NotificationActionType.Foreground)
}),
new NotificationUserCategory("request",new List<NotificationUserAction> {
new NotificationUserAction("Accept","Accept", NotificationActionType.Default, "check"),
new NotificationUserAction("Reject","Reject", NotificationActionType.Default, "cancel")
})
}, false);
#endif
然后我发送了数据信息,我收到了通知,并在打开通知后
CrossFirebasePushNotification.Current.OnNotificationOpened
被击中但从未经过其代码块。