"@react-native-firebase/app": "^6.7.1",
"@react-native-firebase/messaging": "^6.7.1",
"react": "16.8.6",
"react-native": "0.60.5",
我使用redux控制值并导航到另一个屏幕。
以下是我的主页呈现函数下的一些代码:
if (notificationOpen) {
if (notificationTag === 'Mail') {
navigation.navigate('MailScreen');
} else if (notificationTag === 'Bill') {
navigation.navigate('BillboardScreen');
}
defaultNotificationOpen(); // set notificationOpen to false
}
我在应用程序关闭时触发通知,代码如下:
messaging()
.getInitialNotification()
.then(remoteMessage => {
console.log('remoteMessage is', remoteMessage);
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
);
const notificationTag = remoteMessage.notification?.title;
console.log('notificationTag:', notificationTag);
dispatch({ type: NOTIFICATION_TAG, notificationTag });
dispatch({ type: NOTIFICATION_OPEN, notificationOpen: true} );
}
});
这是我在应用程序关闭时收到通知的唯一方法。
但我的问题是,如果我只是重新启动我的应用程序(没有通知),
getInitialNotification()
还在工作而且
notificationOpen