此过程中未初始化默认 FirebaseApp - React Native - 本地通知

Ana*_*ath 3 android react-native react-native-push-notification

(在将此问题标记为重复之前,请阅读整个问题)

我在 React-Native 应用程序中使用react-native-push-notification库。

在我的应用中,我还没有初始化 Firebase,因为我现在不需要任何远程通知。目前我正在安排本地通知,当通知到来时,我期待用户的操作。根据按下的按钮,我想进行适当的 API 调用。

因此,为了实现这一点,我使用了 PushNotification.configure 方法,但它向我抛出“在此过程中未初始化默认 FirebaseApp。确保已初始化 Firebase”错误。

当我完全不需要它时,我被迫使用 Firebase。

有人可以在这里帮助我吗,我过去两天一直在寻找答案。我是 React Native 的新手,我仍在学习它。任何帮助表示赞赏。

谢谢

Ana*_*ath 11

最后我找到了解决方案,它实际上在文档本身中,但我不知何故忽略了。我会在这里发布它,因为我确定那里有像我这样的人。

我们应该增加requestPermissions: Platform.OS === 'ios',PushNotification.configure是这样的:

PushNotification.configure({
    onNotification: function (notification) {
      console.log('LOCAL NOTIFICATION ==>', notification);
    },

    // This line solves the problem that I was facing.
    requestPermissions: Platform.OS === 'ios',
  });
Run Code Online (Sandbox Code Playgroud)

  • 太好了,省了很多力气;) (2认同)