【发布时间】:2020-02-23 04:41:49
【问题描述】:
在react-native-firebase v6 中,我无法让setBackgroundMessageHandler 在我的应用程序中工作。收到通知就好了,但处理程序没有被执行。
我已经像在guide 中那样做了,但无济于事。
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));
});
除了收到的通知之外什么也没发生。我希望代码将传入的通知保存在AsyncStorage。
【问题讨论】:
标签: android react-native react-native-firebase