如何在iCloud中合并冲突的UIDocument

如何在iCloud中合并冲突的UIDocument

本文介绍了iOS:如何在iCloud中合并冲突的UIDocument?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解我的选项是要合并存储在iCloud中的2个或更多冲突版本的UIDocument.在检测到文档冲突之后,我目前使用removeOtherVersionsOfItemAtURL来简单保存文档数据的最新版本.但是,我想支持合并有冲突的文档.

I'm having trouble understanding what my options are to merge 2 or more conflicted versions of a UIDocument stored in iCloud. After detecting the document conflict, I currently use removeOtherVersionsOfItemAtURL to simply keep the latest version of the document's data. However, I would like to support merging conflicted documents.

我发现的唯一资源和教程都涉及Core Data和持久性存储以进行合并,示例中使用了诸如SQLite之类的东西,但我没有使用.就我而言,每个文档都是一个单独的文件.

The only resources and tutorials I found referred to Core Data and persistent stores for merging, and the examples used things like SQLite, which I don't use. In my case, each document is a separate file.

背景:我的应用程序使用自定义的NSObject子类(与属性相关)来存储数据.它们在UIDocument内部进行编码和解码(使用NSCoding + NSKeyedArchiver/NSKeyedUnarchiver).我已经设置了我的应用程序以与iCloud完全兼容.它可以使文件无处不在,反之亦然,可以编辑和删除它们.

Background: My app uses custom NSObject subclasses (with relevant of properties) to store data. They are encoded and decoded (using NSCoding + NSKeyedArchiver/NSKeyedUnarchiver) inside of a UIDocument. I have set up my app to fully work with iCloud. It can make files ubiquitous and vice-versa, edit and delete them.

请帮助我了解如何合并有冲突的UIDocument's

Please help me to understand what I can do regarding merging conflicted UIDocument's!

推荐答案

您将使用NSFileVersion获取文件的冲突版本.当您进入冲突状态时,对于不视为当前"版本的任何版本,+unresolvedConflictVersionsOfItemAtURL都将为您提供NSFileVersion实例.然后,您可以使用NSFileVersionURL属性来获取那些冲突版本的内容.

You'll use NSFileVersion to get conflicting versions of the file. When you get into a conflict state, the +unresolvedConflictVersionsOfItemAtURL will give you NSFileVersion instances for any versions not considered "current". You can then use the URL property of NSFileVersion to get the contents of those conflicting versions.

现在您有多个版本的文档.解决冲突的方式取决于您-遍历冲突的版本并以对文档结构有意义的任何方式合并更改.如果可以用代码解决它,则可能会从一个冲突版本中获取一些数据,并将其复制到当前版本中,直到当前版本包含最终的合并版本为止.

Now you have more than one version of the document. How you resolve the conflict is up to you-- go through the conflicting versions and merge changes in whatever way makes sense for your document structure. If you can resolve it in code, you'll probably take some of the data from one of the conflict versions and copy it into the current version, until the current version contains the final merged version.

完成此操作后,保存文档,删除有冲突的版本(removeOtherVersionsOfItemAtURL:error:),然后将当前文件版本标记为已解决.您可能还想使用removeAndReturnError:摆脱旧版本.

Once you've done that, save the document, remove the conflicting versions (removeOtherVersionsOfItemAtURL:error:), and mark the current file version as resolved. You might also want to use removeAndReturnError: to actually get rid of the older version(s).

有关更多详细信息,请参见 Apple解决文档版本冲突的指南.

Some more detail on this can be found in Apple's guide for resolving document version conflicts.

这篇关于iOS:如何在iCloud中合并冲突的UIDocument?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:57