Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用React-Native firebase在React-Native上定制通知_Firebase_React Native_Push Notification_React Native Firebase - Fatal编程技术网

使用React-Native firebase在React-Native上定制通知

使用React-Native firebase在React-Native上定制通知,firebase,react-native,push-notification,react-native-firebase,Firebase,React Native,Push Notification,React Native Firebase,我正在使用react本机firebase库在应用程序中实现推送通知,但我有一个问题。我需要在我的应用程序中装载自定义通知,并在服务器不向我发送标题/正文的情况下从React组装它们,我需要这些通知,应用程序处于后台并完全关闭 我做了以下尝试,但没有成功 在我的索引中,我注册了我的班级 AppRegistry.registerHeadlessTask( "RNFirebaseBackgroundMessage", () => bgMessaging ); 在我的JS类中,我

我正在使用react本机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发送的通知


感谢并为我的英语感到抱歉。

嗨,请尝试下面的

  • .setNotificationId(“通知操作”)
    更改为
    .setNotificationId(notificationOpen.notification.notificationId)

  • .android.setChannelId(“通知操作”)
    更改为
    .android.setChannelId(notificationOpen.notification.android.channelId)


您好,请尝试下面的

  • .setNotificationId(“通知操作”)
    更改为
    .setNotificationId(notificationOpen.notification.notificationId)

  • .android.setChannelId(“通知操作”)
    更改为
    .android.setChannelId(notificationOpen.notification.android.channelId)


你修好了吗?修好了吗?