对于Firebase的集成与使用,没别的,看文档就行了。
个人使用CocoaPods方式:
pod 'Firebase/Firestore'
我需要在AppDelegate.m获取数据:
- import 库
@import Firebase;
- 配置
[FIRApp configure];
- 获取数据
FIRFirestore *firestore = [FIRFirestore firestore];
FIRDocumentReference *adRef = [[firestore collectionWithPath:@"users"] documentWithPath:@"haha"];
[adRef getDocumentWithSource:(FIRFirestoreSourceServer) completion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) {
if (snapshot.exists) {
// Document data may be nil if the document exists but has no keys or values.
NSLog(@"Document: %@", snapshot.data);
} else {
NSLog(@"Document does not exist");
}
}];
然后获取数据时,遇到报错:
8.6.1 - [Firebase/Firestore][I-FST000001] 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.
8.6.1 - [Firebase/Firestore][I-FST000001] WatchStream (2809da718) Stream error: 'Unavailable: failed to connect to all addresses'
对上以上两个报错,尤其第一条很让人迷惑,很确信当时网络没有问题...
刚开始怀疑集成过程漏掉了什么,重新建了一个firebase项目,按照文档对Cloud Firestore重新来了一遍,依然报同样的错误...
然后google时,搜到Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds #7615这个issue,虽然有点没太看懂,但也基本确定我的问题和这个issue的不一样。
当我打开fq代理后...成功了-_- 天晴了