我使用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在用户点击通知时没有调用。任何人都可以帮忙吗?