I added firebase push notifications to my app.js file as following:
import messaging from '@react-native-firebase/messaging';
async function registerAppWithFCM() {
await messaging().registerDeviceForRemoteMessages();
}
//inside app function:
const unsubscribe = messaging().onMessage(async remoteMessage => {
console.log("Foreground message");
})
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});
Then i sent a notification from the server while app in foreground and it worked (logged "Foreground message"), when i tried it again while app on the background the notification have arrived and logged (Message handled in the background! and the remote message) but when clicked on it to open app it crashed the app (App has stopped), i am using :
"@react-native-firebase/app": "^6.4.0", "@react-native-firebase/messaging": "^6.4.0", "react": "16.11.0", "react-native": "0.62.0",