【发布时间】: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