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:
- I get the data that was created before I started testing on 2 devices
- I get whatever data I created on the device I'm currently using
- 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?