未找到实际的本地firebaseURL

问题描述 投票:0回答:1

[在响应本机中将某些数据推送到firebase时,出现以下错误,即我的firebase数据库URL未定义。我在这里使用android模拟器。也许我缺少一些需要在我的android build gradle文件中推送到Firebase的东西?

我目前也为此应用程序使用firebase auth,它确实可以正常工作,但是我不得不修改android build gradle。我想知道这是否可能是类似的问题?如果是这样,谁知道我需要添加什么?

我是新来的本机抱歉:(

enter image description here

下面是我的配置和我的Firebase应用程序初始化

sendNoteToDatabase = () => {
  const firebaseConfig = {
    apiKey: 'my api key',
    authDomain: '*********-37824.firebaseapp.com',
    databaseURL: 'https://******-37824.firebaseio.com/',
    projectId: '******-23288'
  }

  if (!firebase.apps.length) {
    firebase.initializeApp(firebaseConfig);
  }

  const note = {
    title: "this.state.title",
    who: "this.state.who",
    time: "this.state.time"
  }

  firebase.database().ref('Users/').set(note).then((data) => {
    //success callback
    console.log('data ', data)
  }).catch((error) => {
    //error callback
    console.log('error ', error)
  })
}

我已经检查了URL,并且正在使用实时数据库。我不确定这是我的代码结构问题还是android问题?

android firebase react-native firebase-realtime-database react-native-firebase
1个回答
0
投票

使用Franks Advice,我能够通过使用componentDidMount钩子初始化firebase应用程序来解决此问题


componentDidMount(){
    if (!firebase.apps.length) {
      firebase.initializeApp(firebaseConfig);
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.