【问题标题】:React Native Firebase: Check if module installedReact Native Firebase:检查模块是否已安装
【发布时间】:2020-04-10 06:25:39
【问题描述】:

有什么方法可以预先检查模块(例如通知)是否在 Native 端配置?

例如,我调用firebase.notification() 会导致应用崩溃。在调用notification() 函数之前我会检查一下。

** 我正在使用“react-native-firebase”:“^5.5.6”;

---- 添加 -----

我正在使用 codepush 进行热部署。

问题是,我的 Android 应用 v1.0 没有在原生端 (android) 中配置通知,即没有 new RNFirebaseNotificationsPackage()

新的原生更新v1.1 我在原生代码中添加了new RNFirebaseNotificationsPackage()

通过调用firebase.notification(),应用 v1.0 在 v1.1 工作时崩溃。

我知道检查应用版本可以防止这个问题,但我需要一个直接的解决方案来确保RNFirebaseNotificationsPackage 被集成到本机端。

【问题讨论】:

    标签: react-native react-native-firebase


    【解决方案1】:

    我认为你应该像这样使用通知:

    firebase.notifications()
    

    如果你想预先检查 firebase 是否存在,你可以这样做:

    if (typeof firebase !== 'undefined) {
    

    【讨论】:

    • 检查if (typeof firebase !== 'undefined) { 很好,但我如何检查这个firebase.notifications
    【解决方案2】:

    我遇到了同样的问题,但在我的情况下,这是 Android 和 iOS 版本之间的差异。

    对我有用的解决方案是将 firebase 调用包装在 try/catch 块中以避免崩溃。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多