【问题标题】:Is it possible to open ContentPage when OnMessageReceived from firebase cloud messaging?从 Firebase 云消息传递 OnMessageReceived 时是否可以打开 ContentPage?
【发布时间】:2020-09-22 18:32:38
【问题描述】:

我试图在 fcm 发送推送通知时打开一个 contentPage。我已经学会了如何在单击“推送通知”时打开 contentPage。我的问题是我如何遵循相同的方法但在不点击推送通知的情况下打开 contentPage。这是可能的还是我必须尝试另一种方法来做到这一点?

我浏览了这篇文章:https://forums.xamarin.com/discussion/155333/open-contentpage-when-tap-push-notification-using-firebasepushnotificationplugin

感谢您的帮助。

【问题讨论】:

  • 尝试检测自定义 FirebaseMessagingService 类的 OnMessageReceived 方法直接执行导航。检查代码:public class FirebaseNotificationService : FirebaseMessagingService { public override void OnMessageReceived(RemoteMessage message) { base.OnMessageReceived(message); ... Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new Page_1()); } ... }

标签: android ios xamarin xamarin.forms firebase-cloud-messaging


【解决方案1】:

我如何遵循相同的方法但打开内容页面而不...点击推送通知

尝试检测自定义FirebaseMessagingService类的OnMessageReceived方法直接进行导航。设备收到消息后会打开页面。

检查代码:

public class FirebaseNotificationService : FirebaseMessagingService
{
    public override void OnMessageReceived(RemoteMessage message)
    {
        base.OnMessageReceived(message);
        ...
        Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new Page_1());
    }
    ...
}

【讨论】:

  • 这段代码仅在应用程序处于前台时有效。我想在应用程序被杀死或在后台打开应用程序时做点什么。最终结果将类似于警报应用程序所做的事情,即当我收到通知时,我将向用户显示 AlarmScreen (ContentPage)
  • 自Android 8.0起,后台服务受限。如果您想让服务始终正常工作,请尝试使用ForgroundService。教程:docs.microsoft.com/en-us/xamarin/android/app-fundamentals/…查看链接:stackoverflow.com/questions/60028587/…
猜你喜欢
  • 2016-10-09
  • 2018-08-04
  • 1970-01-01
  • 2018-12-15
  • 1970-01-01
  • 2017-10-24
  • 1970-01-01
  • 1970-01-01
  • 2019-07-12
相关资源
最近更新 更多