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

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

问题描述

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



我最近在应用程序中打开了持久性,如下所示:

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

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