Reputation: 77
I am making a simple quiz app in XCode (Swift 3.0) but have ran into a couple of Firebase related questions that I would really like to get some help with. First, let me explain what I am trying to do:
I want to store the question bank on Firebase so that I can add, remove and update questions and then have them automatically updated on the users' phones without requiring an update through AppStore.
There should be some "meta" data about each user stored on Firebase, such as nickname and a list of id's of the questions completed, so that the same question is not asked twice. The reason I want to have this data on Firebase is that I want to allow users to login from different devices and pick up from where they were before.
If possible, I would like to minimize the number of calls to Firebase so that the app is not using the users' roaming too much.
I have looked at the Firebase Offline Capabilities, and my questions are:
I don't really understand the difference between .isPersistenceEnabled and .keepSynced - if anyone could explain this, I would be very grateful.
For the requirements above, what would you suggest I do (.keepSynced, .isPersistenceEnabled, or anything else?)
Thanks a lot in advance!
Upvotes: 0
Views: 390
Reputation: 317372
Enabling persistence sets up a local disk-based cache of data that has previously been read from Firebase Realtime Database.
keepSynced() on a reference the equivalent of adding an empty listener on a reference. This has the effect of making sure any changes to that location on the server will be automatically downloaded to the client. This does not last after the app has been killed. If you want this enabled all the time, you'll have to code your app to call it every time at launch.
When you use keepSynced() along with enabling persistence, that means the client cache should always contain the most up-to-date data from the server, as long as the client has connectivity to receive those updates. This means that other listeners will receive and cached data immediately from that location.
Upvotes: 2