如何将Firebase对象持久存储到iOS中的磁盘上? [英] How to persist Firebase objects to disk in iOS?

查看:75
本文介绍了如何将Firebase对象持久存储到iOS中的磁盘上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase 的iOS实施似乎不支持客户端模型的脱机缓存.实际上这意味着什么:

It seems that Firebase iOS implementation doesn't support offline caching of the client model. What this means in practice that:

  • 对于需要身份验证的Firebase应用程序,您需要先进行身份验证并等待Firebase完成登录(检查用户身份,打开套接字等),然后才能开始移动数据.视网络状况而定,这将需要1-8秒(通常是2-5),至少在芬兰是这样.
  • 经过身份验证后,Firebase首先下载初始数据集并初始化客户端缓存.执行此操作的时间取决于您为其添加侦听器的数据的大小,但这通常非常快.

这里的问题是,如果您使用Firebase来实现(例如消息传递应用程序),则您最有可能希望向用户显示消息线程和消息的先前缓存版本,然后才与该消息传递者进行实际连接.后端服务器已建立.

The problem here is that if you're using Firebase to implement, for example a messaging app, you'd most likely want to show the user a previously cached version of the message threads and messages, before the actual connection with the backend server is established.

我认为正确的实现方式需要处理:

I'd assume the correct implementation for this would need to handle:

  1. 客户端模型<-> Firebase JSON映射(我将Mantle用于这个)
  2. 将客户端模型持久化到磁盘上(使用NSKeyedArchiver还是Core Data等手动实现?)
  3. 在连接可用时将磁盘上的模型与内存中的Firebase链接的模型同步(手动实现?)

有人(第二方或第三方)提出解决方案来实现2)和3)吗?

Has anyone come up with a solution (own or 3rd party) to achieve 2) and 3)?

推荐答案

自从提出此问题以来,Firebase似乎已经解决了此问题.现在,Firebase的离线功能上有很多资源,包括磁盘持久性.

It seems Firebase has solved this problem since this question was asked. There are a lot of resources on Offline Capabilities now with Firebase, including disk persistence.

对我来说,打开持久性就像在我的AppDelegate中一样简单:

For me, turning on persistence was as simple as the following in my AppDelegate:

Firebase.defaultConfig().persistenceEnabled = true

假设您的应用程序至少已通过互联网连接运行一次,这应该可以很好地加载数据的最新本地副本.

Assuming your app has been run with an internet connection at least once, this should work well in loading the latest local copy of your data.

这篇关于如何将Firebase对象持久存储到iOS中的磁盘上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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