首页 > 解决方案 > 如果关闭或在后台运行,我应该如何在反应原生 Firebase 应用程序中处理推送通知

问题描述

首先如果应用程序关闭:

this.notificationOpenedListener = firebase.notifications()
.getInitialNotification()
.then((notificationOpen: NotificationOpen) => {
if (notificationOpen) {
    // App was opened by a notification
    // Get the action triggered by the notification being opened
    const action = notificationOpen.action;
    // Get information about the notification that was opened
    const notification: Notification = notificationOpen.notification;
}
});

第二,如果应用程序在后台运行:

this.notificationOpenedListener = firebase.notifications()
    .onNotificationOpened((notificationOpen: NotificationOpen) => {
    // Get the action triggered by the notification being opened
    const action = notificationOpen.action;
    // Get information about the notification that was opened
    const notification: Notification = notificationOpen.notification;
 });

如何加入代码第一和第二。

参考:这里有链接

或者如何鞭打应用程序关闭或在后台运行反应原生?

标签: javascriptfirebasereact-nativefirebase-cloud-messaging

解决方案


推荐阅读