In react-native-firebase v6, I can't get setBackgroundMessageHandler
to work in my app. Notifications are received just fine but the handler is not executed.
I have done it like in the guide to no avail.
import { AppRegistry } from 'react-native';
import messaging from '@react-native-firebase/messaging';
import AsyncStorage from '@react-native-community/async-storage';
import App from './App';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, () => App);
messaging().setBackgroundMessageHandler(async ({ data: { title, message } }) => {
console.log('in background');
// Save the notification locally
const notificationList = JSON.parse(await AsyncStorage.getItem('@SM_NOTIFICATIONS')) || [];
notificationList.push({ title, message, isRead: false });
await AsyncStorage.setItem('@SM_NOTIFICATIONS', JSON.stringify(notificationList));
});
Nothing happened beside the incoming notifications. I expected the code to save the incoming notifications in AsyncStorage
.