立即刷新Firebase iOS SDK缓存 [英] Refresh Firebase iOS SDK cache immediatly
问题描述
我最近在应用程序中打开了持久性,如下所示:
$ p $ Fire code $ $ b
效果很好,但现在我的应用程序甚至在连接互联网时也不会刷新数据。我正在使用这里提到的离线功能。
我有与持久性相同的问题,这里有两个解决方案:
< 1)继续使用 observeSingleEventOfType
,但是设置 ref.keepSynced(true)
。这将不会监听您的数据中发生的变化,但一旦执行此代码,它将刷新数据。我已经为我的常见问题部分选择了这个选项,当屏幕打开时(viewDidLoad),只需要更新一次。
$ b 2)使用 observeEventOfType
。这将始终保持您的数据同步,并会在您的数据更改后再次执行。
Is there a way to manually and immediately refresh the Firebase cache, using the iOS SDK, to pull down the latest data (assuming you are online)? For example, if I made some changes to my data on Firebase, I want my app to reflect that immediately, but with persistence turned on, it usually takes a few restarts of the app.
I recently turned on persistence in my app like so:
Firebase.defaultConfig().persistenceEnabled = true
It worked great, but now my app doesn't refresh it's data very often even with an internet connection. I'm using the offline capabilities mentioned here.
I had the same problem with persistence and here are two options solving it:
1) Keep using observeSingleEventOfType
but setting ref.keepSynced(true)
. This won't listen to changes happening in your data but it refreshes data once this code is executed. I've chosen this option for my FAQ section which just needs to update once when the screen is opened (viewDidLoad).
2) Use observeEventOfType
. This will always keep your data in sync and will execute again as soon as your data changes.
这篇关于立即刷新Firebase iOS SDK缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!