1

I have a working implementation of iCloud. Now I want to improve conflict handling by adding some merge functionality. I've been trying to come up with a consistent way of forcing a conflict for testing purposes but I haven't had luck so far, conflicts don't occur consistently when I expect them to occur. This might indicate that I'm doing something wrong, or maybe that I just misunderstood something about how iCloud works (yet another thing, I mean).

I'm using UIDocument and yes, I'm listening to the UIDocumentStateChangedNotification. In fact, I do get some occasional conflict notifications. Also, I only have one file in iCloud.

Having two devices using the same iCloud accout, here is the flow of events I was expecting to always cause a conflict:

  • Open the file on both devices (both devices are now correctly seeing the same content). Note: Here is the only time openWithCompletionHandler is called, after this it's never called again.
  • Make some change on device A and call saveToURL.
  • Wait some time to allow the change to propagate.
  • Make some other change on device B and call saveToURL.
  • Wait some time to allow the change to propagate.
  • EXPECTED: The app should be getting a conflict notification from iCloud. OBSERVED: A conflict does occur very occasionally, but most of the time what happens is simply that the UIDocument gets its UIDocumentStateEditingDisabled flag set and then cleared back after half a second or so (I'd guess editing is being disabled while the iCloud daemon is pulling the version from the other device and saving it in the local ubiquitous directory).

Much like a version control system like SVN, I was expecting the version from device B to cause a conflict because an "update" was required in order to get the version uploaded by device A.

Am I wrong expecting a conflict in the scenario I just described? Why? Is there any other way to consistently force a conflict?

Thanks!

4

2 回答 2

5

我本以为引发冲突的更好方法是:

  • 确保两台设备都有最新的数据副本
  • 将两台设备都置于飞行模式以防止任何 iCloud 更新
  • 在两台设备上更改同一位置的数据,每个设备都有不同的新数据
  • 重新打开网络
  • 等待更改传播

从文档:

当应用程序的两个实例在本地更改文件并且随后将两个更改都传输到 iCloud 时,就会发生冲突。例如,当设备处于飞行模式时进行更改并且无法立即将更改传输到 iCloud 时,可能会发生这种情况。当它发生时,iCloud 会存储文件的两个版本,并通知应用程序的文件提供者发生了冲突并需要解决。

您这样做的方式(允许同步时间,以不同方式更改文档)似乎不应该引起冲突。

于 2012-04-15T12:22:18.480 回答
1

iCloud 的工作原理与版本控制系统基本相同——除了您只能访问冲突版本(发生冲突时)。

ver_1从 iCloud 中提取设备、编辑、保存并发现服务器的版本(ver_2或更新)与预期不同时,将创建一个冲突的版本。

初始同步后,您可以:

  1. 关闭设备 B 上的 wifi,编辑并保存。
  2. 在设备 A 上编辑,保存。
  3. 在设备 B 上打开 wifi。

很快就会发生冲突。

于 2012-05-15T07:59:38.183 回答