6
votes

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?

4
Did you add that plist Google provides? The file named GoogleService-Info.plist?creeperspeak
Yes I added that.Cameron Korb
I have the same issue. It was working fine a few hours back. I guess it's because of Firestore being in beta. Moving to Realtime Database is the only option I see.an23lm
I'm having the same issue as well... Works sporadically. Did you happen to find any solutions?chez.mosey
I never made this work. In my project Analytics work as expected but Firestore never. Getting document fails with "Failed to get document because the client is offline." I also get "Could not reach Firestore backend." Looks like "beta" means "it doesn't work"olejnjak

4 Answers

3
votes

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".

0
votes

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")
    }
}
0
votes

The issue resolved itself when I 'reset all content and settings' on the simulator.

0
votes

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