Reputation: 73
I'm creating a swift 4 ios application and would like to use Firestore to store all my data. 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."
my cocoapods file contains:
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
In AppDelegate
: I import Firebase
and in didFinishLaunchingWithOptions
I do FirebaseApp.configure()
In viewController: import Firebase
(have also tried import FirebaseFirestore
)
I define:
var docRef : DocumentReference!
and in 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."
I have my firestore set to test mode so all reads and writes should be allowed. Anyone of ideas as to why I can't connect to the backend?
Upvotes: 6
Views: 6364
Reputation: 231
In my case, I was trying to add data into "Real-Time Database
" of Firebase Console and then read in my new AngularFire2
app.
Realized after a while that it has to be "Cloud Firestore".
Upvotes: 3
Reputation: 296
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
Upvotes: 0
Reputation: 73
The issue resolved itself when I 'reset all content and settings' on the simulator.
Upvotes: 0
Reputation: 1144
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")
}
}
Upvotes: 0