android - 无法将数据推送到 Firestore 模拟器
问题描述
我是火力基地的新手。而且我无法将数据推送到 Firestore 模拟器。下面是我用来推送数据的代码。'SaveFireStore' 是应该向模拟器发送数据的功能。我正在使用 iPhone 模拟器。
import {View, Button} from 'react-native';
import firebase from '@react-native-firebase/app';
import firestore from '@react-native-firebase/firestore';
// Initialize Firebase
const config = {
apiKey: 'KEY',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
};
if (!firebase.apps.length) {
firebase.initializeApp(config);
const db = firestore();
db.settings({host: 'localhost:8080', ssl: false});
} else {
firebase.app(); // if already initialized, use that one
}
const App = () => {
const SaveFireStore = async () => {
const result = await firestore().collection('testing').doc().set({});
console.log('Result = ', result);
};
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Button title="press" onPress={() => SaveFireStore()} />
</View>
);
};
export default App;```
解决方案
我能够将数据推送到 Firestore 模拟器。我在 firebase 上创建了一个 android 项目(不是 web 项目)。在设置集合中的数据之前,我刚刚添加了以下行。
firestore().settings({ host: "localhost:8080", ssl: false });
注意主机字符串它不是'http://localhost:8080'。如果我尝试使用 http://localhost:8080 那么应用程序崩溃了。
推荐阅读
- c# - UNITY 方法没有重载需要 1 个参数
- android - 字体在模拟器和真实设备中都不会更新
- python - matplotlib - 图对象没有属性“绘图”。参考问题
- autodesk-viewer - 视图立方体不显示在 iPad 上
- ruby-on-rails - Heroku:在 /app/config/storage.yml 中找不到 Active Storage 配置(RuntimeError)
- java - 根据 List 的排序重新排序 Map
- javascript - 如何获得使用 node.js 的文本应用程序的语音?
- python - 在Python中以字符串格式从给定日期创建过去5个日期的列表
- r - 我不记得我是如何制作这个图表的,我必须为其他变量重新创建它。
- rest - [ApiException:调用 CreateEnvelope 时出错:]