I am creating a function to store data through async-storage at FCM's setBackgroundMessageHandler event.
I am using @react-native-firebase/messaging. SetBackgroundMessageHandler is not working.
I followed the tutorial at https://rnfirebase.io/messaging/usage/ios-setup and sent it from the firebase website.
Everything works fine except for the current setBackgroundMessageHandler function.
I've been looking for it for a long time, but I can't find the answer.
I tested it with a real device. The push message is displayed normally, but the setBackgroundMessageHandler event does not occur.
Xcode BackgroundMode ScreenShot
package.json
"@react-native-firebase/app": "^11.2.0",
"@react-native-firebase/messaging": "^11.2.0",
"@react-native-firebase/ml": "^11.2.0",
index.js
import React from 'reactn';
import messaging from '@react-native-firebase/messaging';
import {AppRegistry} from 'react-native';
import App from './App';
messaging().setBackgroundMessageHandler(async remoteMessage => {
// ...is not working
console.log('Message handled in the background!', remoteMessage);
});
function HeadlessCheck({isHeadless}) {
if (isHeadless) {
return null;
}
return <App />;
}
AppRegistry.registerComponent('AppName', () => HeadlessCheck);
App.tsx
React.useEffect(() => {
var _resultList = resultList;
const unsubscribe = messaging().onMessage(async remoteMessage => {
//...is working
}
messaging().onNotificationOpenedApp(remoteMessage => {
//...is working
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
//...is working
}
});
}, []);