我正在我的应用程序中使用react本机防火墙库实现推送通知,但我有一个问题。我需要在我的应用程序中挂载自定义通知,并在没有服务器发送标题/正文的情况下从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();
};但我没有成功。推送由固定标题和身体正常工作的消防基地发出的通知。
谢谢,为我的英语道歉。
发布于 2019-10-08 04:47:02
嗨,请试试下面的内容,
.setNotificationId(notificationOpen.notification.notificationId)
.setNotificationId("notification-action")更改为.android.setChannelId("notification-action")到.android.setChannelId(notificationOpen.notification.android.channelId)https://stackoverflow.com/questions/58274839
复制相似问题