Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Firebase iOS SDK cache immediately

Is there a way to manually and immediately refresh the Firebase cache, using the iOS SDK, to pull down the latest data (assuming you are online)? For example, if I made some changes to my data on Firebase, I want my app to reflect that immediately, but with persistence turned on, it usually takes a few restarts of the app.

I recently turned on persistence in my app like so:

Firebase.defaultConfig().persistenceEnabled = true

It worked great, but now my app doesn't refresh it's data very often even with an internet connection. I'm using the offline capabilities mentioned here.

like image 671
tfrank377 Avatar asked Jan 21 '16 22:01

tfrank377


1 Answers

I had the same problem with persistence and here are two options solving it:

1) Keep using observeSingleEventOfType but setting ref.keepSynced(true). This won't listen to changes happening in your data but it refreshes data once this code is executed. I've chosen this option for my FAQ section which just needs to update once when the screen is opened (viewDidLoad).

2) Use observeEventOfType. This will always keep your data in sync and will execute again as soon as your data changes.

like image 136
Raphael Avatar answered Sep 23 '22 09:09

Raphael