React-Native: Firebase Error: No Firebase App [DEFAULT]已被创建-



当我试图将firebase与我的React Native应用程序连接时,我得到了这个错误。

Firebase错误:No Firebase App [DEFAULT]已创建-调用Firebase App. initializeapp () (App/No - App)

我已经在这里添加了我的代码-

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
// Your web app's Firebase configuration
const RNfirebaseConfig = {
apiKey: "........",
authDomain: "note-app-rn.firebaseapp.com",
projectId: "note-app-rn",
storageBucket: "note-app-rn.appspot.com",
messagingSenderId: ".....",
appId: "......"
};
const app = initializeApp(RNfirebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);

try this,

import firebase from '@react-native-firebase/app';
import '@react-native-firebase/auth';
import '@react-native-firebase/firestore';
const RNfirebaseConfig = {
apiKey: "........",
authDomain: "note-app-rn.firebaseapp.com",
projectId: "note-app-rn",
storageBucket: "note-app-rn.appspot.com",
messagingSenderId: ".....",
appId: "......"
};
let app;
if (firebase.apps.length === 0) {
app = firebase.initializeApp(RNfirebaseConfig )
} else {
app = firebase.app()
}
const db = firebase.firestore();
const auth = firebase.auth();

错误的主要来源与初始化配置设置有关。

检查这个用法;

import firebase from 'firebase/compat/app'
import 'firebase/compat/auth'
import 'firebase/compat/firestore'
export const firebaseConfig = {
apiKey: "............",
authDomain: "............",
projectId: "............",
storageBucket: "............",
messagingSenderId: "............",
appId: "............",
measurementId: "............"
}
if (!firebase.apps.length){
firebase.initializeApp(firebaseConfig);
} 

在迁移到新的React Native架构时发生了吗?

记得更改你的导入:

  • from:@import Firebase;inAppDelegate.m
  • to:#import <Firebase.h>inAppDelegate.mm

相关内容

  • 没有找到相关文章