reactjs - React Native to firestore:Firestore(8.2.1):连接WebChannel传输错误
问题描述
我创建了简单的 React Native 屏幕,可以将数据存储到 Firestore。我试过下面的代码,但它没有工作,而不是抛出一些错误。任何人都可以帮助我吗?
我的代码:
应用程序.js
import React, { Component } from 'react';
import {StyleSheet,Text,View,TextInput,Button,TouchableHighlight} from 'react-native';
import firebase from 'firebase';
import firestore from '@react-native-firebase/firestore';
const firebaseConfig = {
apiKey: "*********************",
authDomain: "test-c78ec.firebaseapp.com",
projectId: "test-c78ec",
storageBucket: "test-c78ec.appspot.com",
messagingSenderId: "106189113329",
appId: "1:106189113329:web:4bf80ec51eba69ab042650",
measurementId: "G-875ZSQLZS4"
};
firebase.initializeApp(firebaseConfig);
export default class App extend components{
check2(){
console.log("level strarted");
firebase
.firestore()
.collection("MyCollection")
.doc("mydoc")
.set({
key: "2",
value: "World",
})
.then((ref) => { console.log(ref);
console.log("sucessssssssssssssss")
});
}
render(){
return(
<View>
<TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={() => this.check2('login')}>
<Text style={styles.loginText}>Store data</Text>
</TouchableHighlight>
</View>
);
}
}
错误
WARN [2021-01-06T10:27:51.153Z] @firebase/firestore: Firestore (8.2.1): Connection WebChannel transport errored: {"a": {"C": null, "K": [Circular], "a": {"A": 0, "B": [U], "C": true, "F": 45000, "G": false, "I": true,
"J": -1, "K": "IKeNE9pC779MSM5Rj_dnMg", "Ka": 5000, "Ma": false, "Na": false, "Oa": false, "P": 0, "Pa": 2, "Qa": undefined, "R": [Object], "S": 0, "T": 45498, "Ta": 1, "U": true, "Ua": 10000, "V": 4, "X": false, "Y": [Object], "a": null, "b": [zd], "c":
[bc], "f": [Z], "fa": false, "g": [Array], "ga": undefined, "h": null, "ha": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel", "i": null, "ia": "", "j": null, "ja": 8, "l": null, "m": null, "ma": 12, "na": [U], "o": 3, "oa":
600000, "pa": "ATXNDTEvJ_SpMuY50LXD23HPyh9-AVCM", "qa": -1, "ra": [Ed], "s": null, "u": 0, "v": "gsessionid"}, "b": {"database": "projects/test-c78ec/databases/(default)"}, "c": {"a": [Object], "b": 4, "src": [Circular]}, "f": {"a": [Circular]}, "i": undefined, "j": false, "l": true, "m": true, "o": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel"}, "defaultPrevented": false, "status": 1, "target": {"C": null, "K": [Circular], "a": {"A": 0, "B": [U], "C": true, "F": 45000, "G": false, "I": true, "J": -1, "K": "IKeNE9pC779MSM5Rj_dnMg", "Ka": 5000, "Ma": false, "Na": false, "Oa": false, "P": 0, "Pa": 2, "Qa": undefined, "R": [Object], "S": 0, "T": 45498, "Ta": 1, "U": true, "Ua": 10000, "V": 4, "X": false, "Y": [Object], "a": null, "b": [zd], "c": [bc], "f": [Z], "fa": false, "g": [Array], "ga": undefined, "h": null, "ha": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel", "i": null, "ia": "", "j": null, "ja": 8, "l": null, "m": null, "ma": 12, "na": [U], "o": 3, "oa": 600000, "pa": "ATXNDTEvJ_SpMuY50LXD23HPyh9-AVCM", "qa": -1, "ra": [Ed], "s": null, "u": 0, "v": "gsessionid"}, "b": {"database": "projects/test-c78ec/databases/(default)"}, "c": {"a": [Object], "b": 4, "src": [Circular]}, "f": {"a": [Circular]}, "i": undefined, "j": false, "l": true, "m": true, "o": "https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel"}, "type": "c"}
预期的:
只需将给定的数据写入 Firestore 数据库。
解决方案
在做了很多事情之后,我得到了这个错误的临时解决方案。解决方案是在 firebase 初始化后添加以下代码。我不知道这是正确的解决方案,但现在工作正常。
firebase.initializeApp(firebaseConfig);
firebase.firestore().settings({ experimentalForceLongPolling: true }); //add this..
推荐阅读
- automationanywhere - 在 Automation Anywhere 中将 PDF 表格提取到 Excel 中
- python - Replacing values from two columns when they are similar
- scala - 在 spark 1.6 中读取逗号分隔的文本文件
- wordpress - WooCommerce CSV 导出 - Excel 中的字符显示不正确
- laravel - 如何使用电子邮件和密码通过 Laravel 基本身份验证登录 Flutter 应用程序
- c# - 尝试使用 Tpm2Lib 创建主键时出现 BadAuth 响应
- android - 如何使用 DateTimeFormatter 转换为字符串
- javascript - 如何将焦点设置在 Vuejs 2 中 v-for 内呈现的 textarea 上?
- gerrit - 如何限制对自定义 gerrit 插件的访问
- apache-spark - 如何修复“BlockManagerMasterEndpoint - 没有更多副本可用于 rdd”问题?