立即刷新Firebase iOS SDK缓存 [英] Refresh Firebase iOS SDK cache immediately

查看:95
本文介绍了立即刷新Firebase iOS SDK缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法手动立即刷新Firebase缓存,使用iOS SDK来下载最新数据(假设您在线)?例如,如果我对Firebase上的数据进行了一些更改,我希望我的应用能够立即反映出来,但是在启用持久性的情况下,通常需要重新启动应用。

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)继续使用 observeSingleEventOfType 但设置 ref.keepSynced(true)。这不会监听数据中发生的变化,但会在执行此代码后刷新数据。我为我的FAQ部分选择了这个选项,只需在屏幕打开时更新一次(viewDidLoad)。

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)使用 observeEventOfType 。这将始终使您的数据保持同步,并在数据更改后立即再次执行。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆