是否有可能保存推送通知(firebase)在异步存储收到的消息?



我需要在我的应用程序的列表中列出通过推送通知已经收到的所有消息。我想将它们保存在异步存储中,但是在后台运行的功能无法执行保存操作。这可能吗?如果是,我该怎么做?

我试图实现的代码:

import 'react-native-gesture-handler';
import { AppRegistry } from 'react-native';
import messaging from '@react-native-firebase/messaging';
import App from './App';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { name as appName } from './app.json';
/**
* Background Received Push Notification Firebase
*/
messaging().setBackgroundMessageHandler(async remoteMessage => {
AsyncStorage.setItem('@myapp:notifications', JSON.stringify({name:'teste'}));
});
AppRegistry.registerComponent(appName, () => App);

我更建议将您发送的消息保存在每个用户的firestorecollection或RTD List中,并将每个用户保存在其uid下。这样你就不用依赖设备是否得到它以及应用是否在焦点上。它将允许每个用户即使在切换设备时也能读取接收到的消息。这就是我如何做到每一个使用FCM的应用程序,需要在UI上单独显示消息,以便以后查看。

最新更新