Reputation: 13620
I'm using Firebase offline in my app, to preserve functionality in the case a user has poor cellular reception.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
let all = FIRDatabase.database().reference(withPath:"all")
all.keepSynced(true)
...
However, I've noticed that data is not always fresh. Sometimes data modified elsewhere does not show up until force quit. Additionally, sometime newly created data does not appear after logging out and logging back in.
Is there a function which will perform a sync manually?
Upvotes: 0
Views: 1819
Reputation: 19339
No, Firebase doesn't export a manual database synchronization API. I suspect they don't because of cloud scalability issues and such.
The best you can do for now is keep using the FIRDatabaseReference.keepSynced
API. The documentation makes this somewhat clear (but it sure could be improved!):
By calling
keepSynced(true)
on a location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location. Additionally, while a location is kept synced, it will not be evicted from the persistent disk cache.
Having said that, it always pays to keep the Fallacies of Distributed Computing in mind when designing networked apps. In particular, the first three comes to mind:
- The network is reliable.
- Latency is zero.
- Bandwidth is infinite.
In other words, design for the worst and hope for the best :-)
Upvotes: 5