Reputation: 115
I'm using Firebase for an iOS app. As the title says, I currently have a problem with keepSynced. It does not synchronize the data immediately.
For example, when I receive a push notification saying that a comment has been posted, the user opens the app and he's taken to a post where the comments are loaded. Now, if the app was not in background, it will have to call .keepSynced on certain children. Although this call happens before the comments are loaded, there is still not enough time, so the comments are loaded locally, missing the last ones.
The same thing happens when the user opens the app and the app and refreshes the feed. The first refresh is being done locally, missing the latest posts. After a few seconds, the .keepSynced method finally kicks in, and I can query the online DB.
I currently call .keepSynced in the appDelegate: didFinishLaunchingWithOptions. In both cases mentioned above, I am using .observeSingleEventOfType. My question is, is there a different way to tell firebase to keep certain children always synchronized? In database rules, maybe? Other thoughts, suggestions are appreciated. Thanks!
Upvotes: 3
Views: 1981
Reputation: 598728
Calling keepSynced(true)
on a node ensures that the Firebase Database client will synchronize that node whenever it has a connection to the database servers. There is no built-in API to keep a node synchronized when there is no such connection.
Upvotes: 3