首页 > 解决方案 > Firestore 未连接反应原生 android

问题描述

如果我在 Web 浏览器中运行但不是在 android 模拟器上运行,Firestore 会连接,也不是在财务设备中。

我得到了休闲错误和一个空的 Array = []

[2021-10-23T19:28:23.329Z]  @firebase/firestore:, Firestore (9.1.3): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\@firebase\util\dist\index.esm2017.js:1754:9 in stringLength
at http://192.168.0.102:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&minify=false:130185:28 in error
at node_modules\@firebase\auth\dist\rn\enum_maps-81db3ff6.js:6991:20 in <global>
at node_modules\@firebase\firestore\dist\index.rn.js:10137:8 in <global>
at http://192.168.0.102:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&minify=false:149276:48 in <unknown>
at node_modules\@firebase\firestore\dist\index.rn.js:10653:10 in <global>
at node_modules\@firebase\firestore\dist\index.rn.js:14006:24 in <global>
at node_modules\@firebase\firestore\dist\index.rn.js:14048:19 in cancel
at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:248:12 in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:112:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:166:14 in _callReactNativeMicrotasksPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:418:41 in callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:393:6 in __callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:370:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue

“firebase”:“^9.1.3”,“react”:“17.0.1”,“react-native”:“^0.66.1”。

import React, { useState,useEffect } from 'react'
import { StyleSheet, Text, View,TouchableOpacity } from 'react-native'
import { auth,db } from '../firebase'
import { collection, getDocs} from 'firebase/firestore';
import { onAuthStateChanged,signOut } from "firebase/auth";
import { useNavigation } from '@react-navigation/core';


const HomeScreen = () => {
const [user, setUser] = useState()
const [trials, setTrials] = useState([])
const trialsCollectionRef = collection(db,"trials")

    useEffect(()=> {
        const getTrials = async () =>{
            const data = await getDocs(trialsCollectionRef)
            console.log(data.docs.map((doc)=>({...doc.data(), id: doc.id})))
            setTrials(data.docs.map((doc)=>({...doc.data(),id: doc.id})))
        }
        getTrials()
    },[])

firebase.js

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
        //...
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app)
const db = getFirestore(app)

export {auth, db}

如果我使用 import { collection, getDocs } from 'firebase/firestore/lite'; 它连接我怎样才能让 Firestore 工作,为什么它会这样?

标签: androidfirebasereact-nativegoogle-cloud-firestoreexpo

解决方案


推荐阅读