代码之家  ›  专栏  ›  技术社区  ›  Morton

如何使用react native firebase控制应用程序关闭时的getInitialNotification()

  •  0
  • Morton  · 技术社区  · 6 年前

    "@react-native-firebase/app": "^6.7.1",
    "@react-native-firebase/messaging": "^6.7.1",
    "react": "16.8.6",
    "react-native": "0.60.5",
    

    我使用redux控制值并导航到另一个屏幕。

    以下是我的主页呈现函数下的一些代码:

    if (notificationOpen) {
      if (notificationTag === 'Mail') {
        navigation.navigate('MailScreen');
      } else if (notificationTag === 'Bill') {
        navigation.navigate('BillboardScreen');
      }
      defaultNotificationOpen(); // set notificationOpen to false
    }
    

    我在应用程序关闭时触发通知,代码如下:

    messaging()
          .getInitialNotification()
          .then(remoteMessage => {
            console.log('remoteMessage is', remoteMessage);
            if (remoteMessage) {
              console.log(
                'Notification caused app to open from quit state:',
                remoteMessage.notification,
              );
    
              const notificationTag = remoteMessage.notification?.title;
    
              console.log('notificationTag:', notificationTag);
              dispatch({ type: NOTIFICATION_TAG, notificationTag });
              dispatch({ type: NOTIFICATION_OPEN, notificationOpen: true} );
            }
          });
    

    这是我在应用程序关闭时收到通知的唯一方法。

    但我的问题是,如果我只是重新启动我的应用程序(没有通知), getInitialNotification() 还在工作而且 notificationOpen

    0 回复  |  直到 6 年前
    推荐文章