Enabling Offline
Grocery stores are notorious for spotty data connections. You’d think they’d all have Wi-Fi by now, but no!
No problem! You’ll set up your database to work offline.
Open AppDelegate.swift and add the following to the end of application(_:didFinishLaunchingWithOptions:)
, before return true
:
Database.database().isPersistenceEnabled = true
Just like that, your app works offline. Once you make a connection, even offline updates that occur across app restarts will apply to your Firebase database. Oooh-ahhhh!
Where to Go From Here?
You can download the completed project files by clicking Download Materials at the top or bottom of the tutorial.
Note: You still have to add your own GoogleService-Info.plist after downloading the final project.
Throughout this tutorial, you’ve learned the basics of Firebase by building a collaborative grocery list app. Along the way, you implemented:
- Saving data to a Firebase database.
- Syncing data in real time.
- Authenticating users.
- Monitoring online user status.
- Enabling offline support.
And you did all this without writing a single line of server code!
To learn more about Firebase, please check out the documentation and the examples provided by Firebase.
If you have any comments or questions about this Firebase tutorial, Firebase or the sample app, please join the forum discussion below!