本文介绍了Firebase SDK,离线数据存储,可选择在以后同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS应用程序中使用Firebase时,我想让用户选择将其数据同步到Firebase云中,或将所有内容保留在本地。我已经看到,Firebase已经在其SDK中引入了该选项,可以脱机并保持数据在线同步,但我不确定该功能的意图。

  //将数据保存在本地。 
[Firebase defaultConfig] .persistenceEnabled = YES;
self.firebase = [[Firebase alloc] initWithUrl:kFirechatNS];
[Firebase goOffline];

从文档看来,goOffline()和离线模式通常被构建来处理设备处于脱机状态的临时期间,并在设备再次联机时将数据同步回到云端。 Firebase离线模式能够处理永久离线情况吗?或者迫使Firebase永久脱机,导致Firebase积累越来越多的元数据,以便永远不会发生与云同步?或者在某个时候丢弃旧的数据?或达到最大高速缓存大小时用完脱机高速缓存磁盘空间?

解决方案

我从Firebase支持部门获得了答案:

虽然您可以使用goOffline()长时间强制客户端脱机,但性能会随着时间的推移而恶化。 Firebase客户端将对中间状态更改进行排队,而不是像服务器那样更新存储状态。


When using Firebase in an iOS app I would want to give the users the option to sync their data into the Firebase cloud or just keep everything local. I've seen that Firebase has introduced the option in their SDK to go offline and keep the data from syncing online but I'm not sure about the intent of the feature.

//Keep data local.
[Firebase defaultConfig].persistenceEnabled = YES;
self.firebase = [[Firebase alloc] initWithUrl:kFirechatNS];
[Firebase goOffline];

From the documentation it seems that the goOffline(), and offline mode in general, is build to handle temporary periods where the device is offline, and sync data back in to the cloud as soon as the device becomes online again. Would the Firebase offline mode be capable of handling a "permanent offline" scenario? Or would forcing Firebase to go "permanently offline" lead firebase to just accumulate more and more "meta data" for a never occurring future sync to the cloud? Or discard old data at some point? Or run out of offline cache disk space when a max cache size is reached ?

解决方案

I got answer from Firebase support:

While you can use goOffline() to force the client offline for a long time, performance will deteriorate over time. The Firebase clients will queue intermediate state changes, instead of updating the stored state as the server does.

这篇关于Firebase SDK,离线数据存储,可选择在以后同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 05:57