Greetings!
We've released a new version of the Objective-C client that has experimental disk persistence support!
Up until now, our offline support has been limited to the lifetime of your app. When your app is killed (either by the user or by iOS), any outstanding writes are lost, and the next time your app starts, we'll have no data cached so events won't fire until you are online again.
With disk persistence, your app should work much better offline. Even after an application restart, we'll still have all of your Firebase data cached. It'll be available offline and when you are next online, any writes you made will get synced back to Firebase.
To use it:
- Download the latest SDK.
- Make sure you add libc++.dylib as a library dependency.
- To enable the feature, before creating your first Firebase reference, call:
[Firebase setOption:@"persistence" to:@YES];
Your app should work more-or-less as usual, but there are a few caveats:
- Transactions are not persisted across application restarts. Any outstanding transactions will be lost if your app restarts.
- To reduce the chance of writes made while offline failing when your app is restarted, we automatically persist the last auth credentials used and restore them when your app restarts. If you don't want this, you can manually call unauth after instantiating firebase.
- You may see stale data in certain cases. In most cases, this will be transient. You'll do an observe, get an immediate event with cached data, and then a subsequent event with the latest server data (assuming you are online).
One potentially non-intuitive case: if you do an observeSingleEvent, the data you get will be whatever we have cached rather than the latest data from the server.
What's next?
We're planning some API improvements to eliminate the above caveats, but we think the existing behavior should be suitable for a lot of apps. We'd love your feedback on this feature and any issues you run into.
Once the feature is completely solid and the API changes we need are in place, we'll be bringing this support to our other platforms (Java and JS). Unfortunately, we don't have any specific timeline for that yet.
Thanks!
-Michael