【发布时间】:2020-05-26 18:10:05
【问题描述】:
您好,我一直在尝试从 React-native App 访问 Firestore
我尝试过的代码
import firebase from '@react-native-firebase/app'
import firestore from '@react-native-firebase/firestore';
import * as Actions from '../../../StateManager/Actions/ActionTypes'
export function getVersion() {
return async (dispatch) => {
/// Method 1
firestore().collection('Versions').get().then(querySnapshot => {
console.log('Snapshot: ' + querySnapshot)
return null
});
/// Method 2
firestore().collection('Versions').get()
.then(querySnapshot => {
console.log(querySnapshot);
console.log(querySnapshot._docs);
})
}
}
我没有工作
配置完成
- 在 Firebase 控制台中使用相同的 BundleID(iOS) 和相同的包 (Android) 设置 Android 和 iOS 应用
- 在 iOS 中添加了 Google-service.plist
- 根据文档在 Android 模块中添加了 Google-Service.json
- 已安装
npm install --save @react-native-firebase/app - 在 React 应用中安装了
npm install —save @react-native-firebase/firestore - 跑
cd iOS/ && pod install它在iOS App中安装了与Firebase和Firestore相关的所有依赖项 - 添加了[FirebaseApp 配置];在 iOS 应用 AppDelegate.h
- 在 Android 应用中手动添加了所有依赖项
- 在 Android 和 iOS 上都构建成功
调试控制台信息:在下面调用我的 getVersion() 时进入调试模式
我经历了很多关于 Stack 的问题都没有得到任何积极的输出
包含的库:
React-Navigation, Redux, redux-thunk, Firebase, Firestore
我的 Store 和 redux 已正确配置,并且 Screen.js(我称之为的根屏幕已正确连接到 Redux 和 store)
下面是我的称呼
componentDidMount() {
this.props.getVersion()
if (Platform.OS === 'android') {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)
}
}
FireStore 结构:
FireStore 规则:
【问题讨论】:
-
正如上面所说,您的 firebase 配置没有问题,但您用来请求这些数据的功能没有问题。
-
你能帮我实现预期的结构化函数吗?我可以用它来获取数据
-
我相信这里的问题是你使用
firestore作为一个函数,但它是一个对象。尝试使用firestore而不是firestore()。
标签: firebase react-native google-cloud-firestore react-redux