美文网首页
Google Cloud Firestore

Google Cloud Firestore

作者: QYCD | 来源:发表于2021-09-06 15:36 被阅读0次

    对于Firebase的集成与使用,没别的,看文档就行了。
    个人使用CocoaPods方式:

    pod 'Firebase/Firestore'
    

    我需要在AppDelegate.m获取数据:

    1. import 库
    @import Firebase;
    
    1. 配置
    [FIRApp configure];
    
    1. 获取数据
    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代理后...成功了-_- 天晴了

    相关文章

      网友评论

          本文标题:Google Cloud Firestore

          本文链接:https://www.haomeiwen.com/subject/irnewltx.html