使用React-Native firebase在React-Native上定制通知
我正在使用react本机firebase库在应用程序中实现推送通知,但我有一个问题。我需要在我的应用程序中装载自定义通知,并在服务器不向我发送标题/正文的情况下从React组装它们,我需要这些通知,应用程序处于后台并完全关闭 我做了以下尝试,但没有成功 在我的索引中,我注册了我的班级使用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类中,我
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)