Are you using react-native-firebase lib? If not I hight recommend it. The API provides two APIs to handle notification interactions.
- getInitialNotification: When the application is opened from a quit state.
- onNotificationOpenedApp: When the application is running, but in the background.
useEffect(() => {
// Assume a message-notification contains a "type" property in the data payload of the screen to open
messaging().onNotificationOpenedApp(remoteMessage => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
navigation.navigate(remoteMessage.data.type);
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
);
setInitialRoute(remoteMessage.data.type); // e.g. "Settings"
}
setLoading(false);
});
}, []);
Please, check the documentation at the Notification Handling Interaction Section
CLICK HERE to find out more related problems solutions.