I am developing a React Native app and am facing an issue with Firebase Cloud Messaging. The base notification functionality works well and has been used to send a number of notifications in production. However, I am trying to enhance my notification ability by triggering an in-app action when my app is opened via a notification press (currently, opening via notification takes the user to the home page).
I successfully implemented this in the iOS simulator – I click the notification and the action is triggered as expected. However, it is not working in Testflight. I am only concerned with what occurs when the app is in the background, and this is what I am testing in both scenarios (simulator vs. testflight)
I am using @react-native-firebase/messaging
and am not using any third-party libraries such as Notifee
The payload I am sending is: data: {“action”:”open_x_screen”}
This is the handler for the notification, found in my App.js
useEffect(() => {
// Function to handle notification open
const handleNotificationOpen = (remoteMessage) => {
if (remoteMessage && remoteMessage.data && remoteMessage.data.action) {
const action = remoteMessage.data.action;
if (navigationRef.isReady()) {
switch(action) {
case 'open_x_screen':
navigationRef.navigate('x_screen', { button: 'x' });
break;
case 'open_y_screen':
console.log("Received")
navigationRef.navigate('y_screen', { button: 'y' });
break;
case 'open_z_screen':
navigationRef.navigate('z_screen', { button: 'z' });
default:
break;
}
}
}
};
messaging().onNotificationOpenedApp(handleNotificationOpen);
messaging().getInitialNotification().then(handleNotificationOpen);
}, []);
I have not included the rest of my App.js because I believe this is more configuration related than code related, and I do not think the issue has to do with my use of navigationRef or other parts of my App.js. I am making this assumption based on the fact that it works in the simulator but not in Testflight