1

My iOS app is using Google's Firebase as its back-office.

As I want my app to work offline, I set it up:

FIRDatabase.database().persistenceEnabled = true

My problem is that now, by observing single events in my database, I get different query results on my 2 test devices. For each device:

  1. I get the data that was created before I started testing on 2 devices
  2. I get whatever data I created on the device I'm currently using
  3. But I can't get whatever data I created on the other device

So it acts as if the cache is never invalidated and the SDK never tries to send a request to the server to see if some updates happened.

I found a workaround to force fetching data online, by calling keepSynced:

let myRef = FIRDatabase.database().reference(withPath: "foo/bar")
myRef.keepSynced(true)
myRef.observeSingleEvent(
        of: .value,
        with: { (snapshot) in
            myRef.keepSynced(false)
            // Do whatever
        })

Reading Firebase's documentation about offline capabilities, I felt the synchronisation was always happening based on network reachability but it seems you need to manually ask for synchronization, which feels awkward. Is this a bug in Google's SDK? Am I misusing it?

Mick F
  • 7,312
  • 6
  • 51
  • 98
  • Using disk persistence does not combine well with using single value event listeners. See http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent/34487195#34487195 – Frank van Puffelen Feb 23 '17 at 18:34
  • Thanks @FrankvanPuffelen. It makes things clearer even though that could deserve a fix or more documentation from Firebase teams. ;) – Mick F Feb 27 '17 at 16:52

0 Answers0