Sending a data-only notification from FCM to a react-native iOS app in foreground is not received by react-native-firebase/messaging onMessage() method. However it works for an android app and for iOS if we send data + notification message. A notification-only message works completely fine on iOS and android getting this issue for data-only message.
I have used a real device to test this and also tried to send content_available parameter with the payload but that didn't work for me.
package.json
"@react-native-firebase/app": "10.0.0",
"@react-native-firebase/crashlytics": "10.0.0",
"@react-native-firebase/messaging": "10.0.0"
Podfile
pod 'Firebase/Core'
pod 'Firebase/Firestore'
pod 'Firebase/Messaging'
Payload
{
"token":"TOKEN",
"data":{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
App.js
async componentDidMount() {
//Get notification permission from user and token
await this.checkPermission();
messaging().onMessage(async remoteMessage => {
console.log("Remote notification inside onMessage" + JSON.stringify(remoteMessage));
});
messaging().onNotificationOpenedApp(remoteMessage => {
console.log('Notification caused app to open from background state:', remoteMessage);
});
// 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,
);
}
});
}