【问题标题】:React-Native: Firebase Error: No Firebase App [DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app) site:stackoverflow.comReact-Native:Firebase 错误:没有创建 Firebase App [DEFAULT] - 调用 Firebase App.initializeApp() (app/no-app) 站点:stackoverflow.com
【发布时间】:2021-09-13 00:30:06
【问题描述】:

尝试使用 redux 从 firebase 读取数据时出现以下错误。

React-Native:Firebase 错误:没有创建 Firebase 应用 [DEFAULT] - 调用 Firebase App.initializeApp() (app/no-app)

与 firebase 的连接工作正常,因为我可以创建一个新用户并将新数据添加到 Firestore。

  1. 我已经添加了我的 info.plist 文件
  2. 我在应用委托中有配置 firebase
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }

我的 redux Actions.js

import firebase from 'firebase/app';
import 'firebase/firestore';

import { USER_STATE_CHANGE, CLEAR_DATA, } from '../constans/index'


//fetch UserInfo from firebase
export function fetchUser() {
  return (dispatch) => {
    firebase
      .firestore()
      .collection("users")
      .doc(firebase.auth().currentUser.uid)
      .get()
      .then((snapshot) => {
        if (snapshot.exists) {
          dispatch({ type: USER_STATE_CHANGE, currentUser: snapshot.data() });
        } else {
          console.log('does not exist');
        }
      });
  };
}

所以有没有人知道我应该做什么。如果我在 Xcode 中添加了“配置”,我应该在 App.js 中也这样做吗?

【问题讨论】:

    标签: ios firebase react-native


    【解决方案1】:

    您需要像这样在应用程序中初始化 firebase 配置文件:

    const reactNativeFirebaseConfig = {
        apiKey: ...,
        authDomain: '...',
        databaseURL: ...,
        projectId: ...,
        storageBucket: ...,
        messagingSenderId: ...,
        appId: ...,
    };
    
    
    if (firebase.apps.length === 0) {
        firebase.initializeApp(reactNativeFirebaseConfig);
    }
    
    firebase.firestore();
    

    【讨论】:

    • 嗯,好吧,但是我找到了我的 api 密钥,authdomain。等等?当我在 firebase 中创建“网络应用程序”时,我会在“设置”下找到所有这些信息。但是对于这个项目,我为 IOS 和 Android 创建了一个。
    • 转到firebase仪表板,左上角您可以看到项目概述旁边的设置图标,单击该图标并选择项目设置,您可以在常规下找到所需的数据。
    • 嗯,好吧,我刚刚添加了一个 Web 应用程序,然后我就获得了所有信息。但我有点困惑,但它现在有效。谢谢
    • 稍后在您尝试在商店中发布之前,您还必须创建一个 iOS 和一个 Android 应用程序并下载 google-service.json 并将其粘贴到 iOS 和 Android 文件夹中的正确文件夹中.如果您需要帮助,请回来。 :)
    猜你喜欢
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 2021-06-12
    • 2021-07-25
    • 1970-01-01
    • 2021-07-21
    • 2020-12-11
    相关资源
    最近更新 更多