[英]Could not Reach Firestore Backend
I'm creating a swift 4 ios application and would like to use Firestore to store all my data.我正在创建一个 swift 4 ios 应用程序,并想使用 Firestore 来存储我的所有数据。 I've gone through the getting started guides and watched the online tutorial, but I continue to get the error:
我已经阅读了入门指南并观看了在线教程,但我仍然收到错误消息:
"4.8.1 - [Firebase/Firestore][I-FST000001] Could not reach Firestore backend."
“4.8.1 - [Firebase/Firestore][I-FST000001] 无法访问 Firestore 后端。”
my cocoapods file contains:我的 cocoapods 文件包含:
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
In AppDelegate
: I import Firebase
and in didFinishLaunchingWithOptions
I do FirebaseApp.configure()
在
AppDelegate
:我import Firebase
并在didFinishLaunchingWithOptions
执行FirebaseApp.configure()
In viewController: import Firebase
(have also tried import FirebaseFirestore
)在 viewController:
import Firebase
(也试过import FirebaseFirestore
)
I define:我定义:
var docRef : DocumentReference!
and in viewDidLoad:在 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)
}
and I get the error我得到了错误
"4.8.1 - [Firebase/Firestore][I-FST000001] Could not reach Firestore backend."
“4.8.1 - [Firebase/Firestore][I-FST000001] 无法访问 Firestore 后端。”
I have my firestore set to test mode so all reads and writes should be allowed.我将我的 firestore 设置为测试模式,因此应该允许所有读取和写入。 Anyone of ideas as to why I can't connect to the backend?
关于为什么我无法连接到后端的任何想法?
In my case, I was trying to add data into " Real-Time Database
" of Firebase Console and then read in my new AngularFire2
app.就我而言,我试图将数据添加到 Firebase 控制台的“
Real-Time Database
”中,然后在我的新AngularFire2
应用程序中读取AngularFire2
。 Realized after a while that it has to be "Cloud Firestore".一段时间后意识到它必须是“Cloud Firestore”。
You first need to get reference to the collection containing that document, try:您首先需要获取对包含该文档的集合的引用,请尝试:
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")
}
}
当我在模拟器上“重置所有内容和设置”时,问题自行解决。
Maybe it is late but I just resolved this problem and it was hard to find the answer so I share it.也许已经晚了,但我刚刚解决了这个问题,很难找到答案,所以我分享了它。 You have to sign in first and the problem will be solved.
您必须先登录,问题才会得到解决。 The code below is an example for sign in with Anonymous user.
下面的代码是使用匿名用户登录的示例。 Hope it is useful for you
希望对你有用
Auth.auth().signInAnonymously { (result, error) in
print("result:\(result) " )
print("error: \(error)")
}
refer: https://firebase.google.com/docs/auth/ios/custom-auth参考: https : //firebase.google.com/docs/auth/ios/custom-auth
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.