0
votes

I am trying to check for errors while the app is trying to connect to the firebase-realtime-database.

My main concern is when the user fires up the app for the first time, but with no internet connection. I create the ref to the database and try to observe a single event, but the console log starts to throw error messages and none of them is captured by my code.

//------- variable declaration

var ref:DatabaseReference?

//------- inside de method

ref = Database.database().reference(withPath: "myPath")

ref?.observeSingleEvent(of: .value, with: { (snapshot) in

    //I cannot even fire up the observer, so I never get here

}){(error) in

    //no error is captured here also

}

Even if I comment or delete the observeSingleEvent I can see the errors getting thrown in the console, but I would like to capture them. Does anyone know how to do that?

Thanks in advance

1

1 Answers

1
votes

It is not an "error" to be offline at the time of a query. The SDK will continue trying to make the request for as along as your app is running and your code has an observer attached at that location.

If you want to detect the connection state, you can attach an observer at /.info/connected to get a callback that indicates the current state of the connection. Note that this information might be out of date, as a stalled connection doesn't immediately become fully disconnected until after a while.