gpt4 book ai didi

firebase - 使用 react-native-firebase 在 React Native 上自定义通知

转载 作者:行者123 更新时间:2023-12-05 07:18:25 28 4
gpt4 key购买 nike

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

我做了以下尝试,但无济于事。

在我的索引中我注册了我的类(class)

  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("notification-action") 更改为 .setNotificationId(notificationOpen.notification.notificationId)

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

关于firebase - 使用 react-native-firebase 在 React Native 上自定义通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58274839/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com