【问题标题】:react-native-firebase: onNotificationOpenedApp and getInitialNotification not working on iOSreact-native-firebase:onNotificationOpenedApp 和 getInitialNotification 在 iOS 上不起作用
【发布时间】:2020-09-20 17:28:00
【问题描述】:

我正在使用 react-native-firebase 7.0.1 中的云消息传递。

我不想将 iOS 设备令牌存储在 Firebase 中,所以我使用 getAPNSToken() 方法,然后将其存储在我的后端。

我可以在设备上发送通知,按下它后,应用程序就会打开。

但是当我尝试从getInitialNotification()onNotificationOpenedApp() 获取消息时,它总是返回null/undefined

它每次都可以在 Android 上运行。

PushHandler.js

import React from 'react';
import messaging from '@react-native-firebase/messaging';

export default class PushHandler extends React.Component {
  constructor(props) {
    super(props);
    this.messageApp = messaging();
  }

  componentDidMount() {
    this.messageApp.onNotificationOpenedApp(remoteMessage => {
      if (remoteMessage) { // <- always null on iOS
        // handle notification
      }
    });

    this.messageApp.getInitialNotification().then(initialMessage => {
      if (initialMessage) { // <- always undefined on iOS
        // handle notification
      }
    });
  }
  render() {
    return null;
  }
}

【问题讨论】:

  • 我遇到了同样的问题,现在正在解决它。如果我弄清楚了,会告诉你的。您在这方面取得了进展吗?
  • 我也面临同样的问题。 @LouieAnderson-你能分享一下你是如何解决这个问题的吗?

标签: ios firebase react-native push-notification react-native-firebase


【解决方案1】:

刚刚意识到根据文档,这些功能仅在通过 FCM 发送和接收通知时有效,这就是为什么您在通过 APNS 手动发送通知时看不到这些功能的原因。

这个包将允许利用 getInitialNotification 和其他功能:https://github.com/react-native-community/push-notification-ios

【讨论】:

    【解决方案2】:

    它以前可以工作。我的意思是,对于 RNFirebase 5.x.x 版本。 出于某种原因,库的维护者决定仅在 Firebase 云消息通过时将这些事件发送到 JS 层。

    这是 IF 语句:
    https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/ios/RNFBMessaging/RNFBMessaging%2BUNUserNotificationCenter.m#L89

    我删除了 IF 语句,它似乎像以前一样工作。 但是,是的,这是 RN-Firebase 库的新行为。

    【讨论】:

      猜你喜欢
      • 2019-01-14
      • 2021-12-18
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多