我正在努力增强现有应用程序以使用 iCloud,以便可以在多个设备上访问相同的数据。
我打算使用基于文档的存储并使用文件包(即表示为单个文件并由 NSFileWrapper
处理的文件目录)。
我的主要问题是:文件包更新是否保证是原子的?如果我打开应用程序并更改了单个文档包中的几个文件,iOS 是否会下载它们,然后仅在所有子文件都存在且就位时通知我的应用程序?或者是否存在文件将一个接一个地传入的风险,给我留下一个可能不一致的包?
此外,我现有的应用程序使用 SQLite(不是通过 Core Data,而是通过自定义包装器)。应用程序的某些部分显然需要一个良好的索引 SQL 数据库来提高性能。所以我的计划是使用 iCloud 数据作为引用存储,出于性能原因(或设备本地的其他地方)在 Caches
目录中保留一个 SQLite 数据库,并根据其中的内容更新数据库云。用户在应用程序中所做的更改将同时记录在 iCloud 和本地数据库中。这是疯狂还是合理?
最佳答案
所以我对你的主要问题的回答是学术性的,因为我没有测试这个的测试基础,但是......
鉴于您的目录被视为单个实体,如果您协调使用该实体作为 NSManagedDocument 操作的项目。
我的回答基于我在学习使用 NSManagedDocument 管理 iCloud 时的笔记:
// Conflict
// - what if a device detached from the network changed a document that another device changed?
// and then the detached device re-attached and tried to apply the change and it conflicted?
// one must manage the conflict by looking for the InConflict document state.
// - when it happens, a decision must be made which version of the document to use and/or
// manage changes. probably want to set NSManagedObjectContext's mergePolicy to other than
// default (Error).
// - then update the old, conflicting NSFileVersion to no longer conflict (and remove those
// versions).
(是的,我以 objective-c 评论格式做笔记。)
关于ios - 将现有的 SQLite iOS 应用程序迁移到 iCloud : how atomic is iCloud?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12065253/