Я реализую push-уведомления в своем приложении с использованием библиотекиact-native-firebase, но у меня есть вопрос. Мне нужно смонтировать пользовательские уведомления в моем приложении и собрать их из React без сервера, отправляющего мне Title / Body, мне нужны эти уведомления с приложением в фоновом режиме и полностью закрытым.
Я предпринял следующую попытку,но безрезультатно.
В моем индексе я зарегистрировал свой класс
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();
};
Но я не былуспешный. Push-уведомления, отправленные из firebase с фиксированным названием и телом, работают нормально.
Спасибо и извините за мой английский.