android - 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 工作,为什么它会这样?
解决方案
推荐阅读
- arrays - 如何通过R中数组中N个元素的索引计算平均值
- angular - NO_ERRORS_SCHEMA 停止以角度工作的 Karma 测试
- authentication - Active Directory .Net Core Web API 认证 JWT
- postgresql - PostgreSQL:无法连接到服务器:端口 5432 上的 TCP/IP 连接
- python - Django NameError:请求未在基于类的视图中定义
- javascript - 嵌入缩略图 Youtube 视频
- javascript - 有没有办法从 ArrayBuffer 中创建 TypedArray 而无需在 Javascript 中使用 new 关键字?
- function - 将函数映射到 Julia 中的稀疏矩阵数组
- google-api - 您可以将 Google Photo API 与 Google 选择器一起使用吗?
- javascript - 如何设置元素的高度以匹配缩放 div 的偏移速度?