React本机应用程序上的rnfirebase不起作用

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

我有这个依赖项:

"react-native": "0.62.2",
"@react-native-firebase/app": "^7.0.1",
"@react-native-firebase/firestore": "^7.0.1",

在我的项目中,我已经通过以下网址在现有项目中完成了rnfirebase结构:react native firebase

我添加了这个:

buildscript {
  dependencies {
    // ... other dependencies
    classpath 'com.google.gms:google-services:4.2.0'
    // Add me --- /\
  }
}

到我的build.gradle

还有这个:

apply plugin: 'com.google.gms.google-services'

对于我的app / build.gradle,还将从Firebase控制台下载的google-services.json放在/ app目录中

然后,我使用了像这样的firestore软件包:

import firestore from '@react-native-firebase/firestore';
useEffect(() => {
    console.log('on load');

    firestore()
      .collection('users')
      .add({
        name: 'Hello firebase',
      })
      .then(() => {
        console.log('success');
      })
      .catch(err => console.log(err, 'error'));
  });

在我的应用中,但请注意,在本机调试器中未建立任何xhr连接,没有控制台日志错误或成功!没事!

我已经完成了卸载rnfirebase / app和rnfirebase / firestore软件包的卸载,然后通过react-native run-android重建了应用程序,但没有任何反应!

firebase react-native google-cloud-firestore react-native-firebase
1个回答
0
投票

经过三天的努力,我只是发现了问题,这是模拟器的互联网连接!!

使用Google搜索应用,我可以连接网络,但是在我的应用上没有可以连接到Firebase的互联网连接!因此解决方案是通过以下命令在特定的dns上运行模拟器:

emulator -avd Pixel_2_API_29  -dns-server 8.8.8.8
© www.soinside.com 2019 - 2024. All rights reserved.