后台作业中的远程消息

时间:2019-02-24 10:09:56

标签: reactjs firebase react-native

我正在使用RNF,Redux和redux-persist。

RNF如https://rnfirebase.io/docs/v5.x.x/messaging/receiving-messages#4)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background

中所述在后台作业中接收消息

我的代码如下:

import firebase from 'react-native-firebase';
import type { RemoteMessage } from 'react-native-firebase';
import notifiaction from './Notifications/MessageNotification'
import {store} from "./Store/MainReduxStore";
import { addNotification } from "./Data/MessageActions"
import { persistStore} from 'redux-persist'
const PATTERN = [1000, 2000, 3000];

export default async (message: RemoteMessage) => {
    firebase.notifications().displayNotification(notifiaction(message));
    let persistor = persistStore(store, null, () => {
       store.dispatch(addNotification(message));
    });

    return Promise.resolve();
}

基本上,我在后台收到消息后,想要:

  1. 根据此消息显示通知构建-> 此工作
  2. 使用Redux保存通知数据以进行存储,并将其持久化到AsyncStorage中,因此稍后在我打开App时,会显示从Redux存储中作为道具加载的新通知-> 这始终不起作用

问题是,在真实设备中运行了几个小时的代码后,代码的第二部分并不总是可以正常工作...没有通知会添加到存储中,因为当我打开应用程序时,我看不到任何新的通知数据主要组件,但我可以看到通知始终会生成并显示。那么第二部分代码可能是什么问题:

let persistor = persistStore(store, null, () => {
       store.dispatch(addNotification(message));
});

应用程序运行几个小时后没有执行任何操作...

0 个答案:

没有答案
相关问题