【问题标题】:Custom notification on React Native using react-native-firebase使用 react-native-firebase 在 React Native 上自定义通知
【发布时间】:2019-10-07 18:00:04
【问题描述】:

我正在使用 react-native-firebase 库在我的应用程序中实现推送通知,但我有一个问题。我需要在我的应用程序中安装自定义通知,并从 React 组装它们而无需服务器向我发送标题/正文,我需要这些通知与应用程序在后台并完全关闭。

我做了以下尝试,但没有成功。

在我的索引中我注册了我的班级

  AppRegistry.registerHeadlessTask(
  "RNFirebaseBackgroundMessage",
  () => bgMessaging
 );

在我的JS类中,我是这样处理的


import firebase from "react-native-firebase";

import type { NotificationOpen } from "react-native-firebase";

export default async (notificationOpen: NotificationOpen) => {
  if (notificationOpen) {
    const notification = new firebase.notifications.Notification()
      .setTitle("Android Notification Actions")
      .setBody("Action Body")
      .setNotificationId("notification-action")
      .setSound("default")
      .android.setChannelId("notification-action")
      .android.setPriority(firebase.notifications.Android.Priority.Max);
    // Build an action
    const action = new firebase.notifications.Android.Action(
      "snooze",
      "ic_launcher",
      "My Test Action"
    );
    // This is the important line
    action.setShowUserInterface(false);
    // Add the action to the notification
    notification.android.addAction(action);

    // Display the notification
    firebase.notifications().displayNotification(notification);
  }

  return Promise.resolve();
};

但我没有成功。从具有固定标题和正文的 Firebase 发送的推送通知正常工作。

感谢和抱歉我的英语。

【问题讨论】:

  • 你修好了吗?

标签: firebase react-native push-notification react-native-firebase


【解决方案1】:

您好,请尝试以下操作,

  • 将.setNotificationId("notification-action") 更改为.setNotificationId(notificationOpen.notification.notificationId)

  • 将.android.setChannelId("notification-action")更改为.android.setChannelId(notificationOpen.notification.android.channelId)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多