Writing and Reading data to Realtime Database when offline

60 views
Skip to first unread message

Rahul Kesharwani

unread,
Apr 12, 2024, 10:25:47 PM4/12/24
to Firebase Google Group
Hi

I am using Realtime Database in my iOS app to store a simple count (number) for an item. 
I have enabled persistence. I want to understand what is the expected write and read behaviour when the device is offline. Lets assume I do following steps:

  1. The device is online. I read the data using the method getDataWithCompletionBlock:. I get the current value for the count stored in the database on server. All good.
  2. The device is offline. I set a new count using the method setValue:withCompletionBlock. The completion callback is not called and I think its expected because it is called when data is written to Firebase server. It gets called as soon as the device goes online. However, I continue to keep the device offline for now.
  3. The device is still offline. I read the data that I had written in step 2 using getDataWithCompletionBlock: method. I do not get the updated value. I still get the value that is read and persisted at step 1.
Is this expected? I was expecting that the local cache would have the updated value for count written at step 2 and that would be returned while reading it at step 3. I require this so that any subsequent operations in my app continue to use the updated values rather than the old value. Eventually the value would be updated to Firebase servers when the device goes online.

Can someone help me to understand if this is the expected behaviour or am I doing something wrong?

Thanks & Regards
Rahul
Reply all
Reply to author
Forward
0 new messages