无法到达Firestore后端

Cam*_*orb 6 ios firebase swift swift4 google-cloud-firestore

我正在创建一个swift 4 ios应用程序,并希望使用Firestore来存储我的所有数据.我已经阅读了入门指南并观看了在线教程,但我仍然收到错误消息:

"4.8.1 - [Firebase/Firestore] [I-FST000001]无法访问Firestore后端."

我的cocoapods文件包含:

pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
Run Code Online (Sandbox Code Playgroud)

AppDelegate:我import FirebasedidFinishLaunchingWithOptionsFirebaseApp.configure()

在viewController中:( import Firebase也试过import FirebaseFirestore)

我定义:

var docRef : DocumentReference! 
Run Code Online (Sandbox Code Playgroud)

并在viewDidLoad中:

docRef = Firestore.firestore().document("test/test")

docRef.getDocument { (docSnapshot, error) in
   guard let docSnapshot = docSnapshot, docSnapshot.exists else {return}
   let myData = docSnapshot.data()
   let val = myData!["name"] as? integer_t ?? 1
   print(val)
}
Run Code Online (Sandbox Code Playgroud)

我得到了错误

"4.8.1 - [Firebase/Firestore] [I-FST000001]无法访问Firestore后端."

我将我的firestore设置为测试模式,因此应允许所有读写操作.任何想法为什么我无法连接到后端?

orx*_*elm 0

您首先需要获取对包含该文档的集合的引用,请尝试:

let docRef = db.collection("test").document("test")

docRef.getDocument { (document, error) in
    if let document = document {
        print("Document data: \(document.data())")
    } else {
        print("Document does not exist")
    }
}
Run Code Online (Sandbox Code Playgroud)