Я использую React Native Firebase для отправки и получения уведомлений в приложении React Native.
Когда получено сообщение, и пользователь нажимает на уведомление, мне требуется функция обратного вызова для получения клавиши действия уведомления для навигации пользователя ксоответствующая навигация.Мой код, как показано ниже:
manifest.js
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
</activity>
код JavaScript для уведомления в компоненте сделал функцию монтирования:
this.messageListener = firebase.messaging().onMessage((message) => {
// Process your message as required
console.log('notification message received', 'Process your message as required', message);
});
// Build a channel
const channel = new firebase.notifications.Android.Channel(Config.ANDROID_CHANNEL_ID, Config.ANDROID_CHANNEL_NAME, firebase.notifications.Android.Importance.Max)
.setDescription('IDPay android channel');
// Create the channel
firebase.notifications().android.createChannel(channel);
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
console.log('notifications onNotificationOpened', notificationOpen);
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
});
firebase.notifications().getInitialNotification()
.then((notificationOpen: NotificationOpen) => {
console.log('notifications getInitialNotification 1', notificationOpen);
if (notificationOpen) {
console.log('notifications getInitialNotification 2', notificationOpen);
// App was opened by a notification
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
}
});
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
console.log('notifications onNotificationDisplayed', notification);
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
});
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
// Process your notification as required
console.log('notifications onNotification', notification);
notification.android.setChannelId(Config.ANDROID_CHANNEL_ID);
notification.android.setAutoCancel(true);
firebase.notifications().displayNotification(notification);
});
В этом коде firebase.notifications () .getInitialNotification не вызывается, когда пользователь нажимает на уведомление.Кто-нибудь может помочь, почему?