当 URL 报告 NSURLUbiquitousItemHasUnresolvedConflictsKey 为 true 但没有其他版本的 URL 时,这意味着啥?

Posted

技术标签:

【中文标题】当 URL 报告 NSURLUbiquitousItemHasUnresolvedConflictsKey 为 true 但没有其他版本的 URL 时,这意味着啥?【英文标题】:What does it mean when a URL reports true for NSURLUbiquitousItemHasUnresolvedConflictsKey but there are no other versions of the URL?当 URL 报告 NSURLUbiquitousItemHasUnresolvedConflictsKey 为 true 但没有其他版本的 URL 时,这意味着什么? 【发布时间】:2012-06-20 17:54:12 【问题描述】:

为了测试冲突,我一直在两台设备上保存同一文档的两个不同版本。在这两种设备上,我将能够查看currentVersionOfItemAtURL 以查看“获胜”版本 - 这在两台设备上都是相同的 - 以及 otherVersionsOfItemAtURLremoveOtherVersionsOfItemAtURL 以查看其他设备。

但是我现在似乎有一个处于奇怪状态的文档,其中currentVersionOfItemAtURL 在两个设备上是不同的,并且没有otherVersionsOfItemAtURLremoveOtherVersionsOfItemAtURL。使用 getResourceValue:forKey:NSURLUbiquitousItemHasUnresolvedConflictsKey 报告 URL 存在未解决的冲突,但我无法看到它们。

当一个 URL 报告 NSURLUbiquitousItemHasUnresolvedConflictsKey 为 true 但没有其他版本的 URL 时,这意味着什么?这是我需要在生产应用中处理的情况吗?

【问题讨论】:

@Simon - 你明白了吗?你能补充一下答案吗? 【参考方案1】:

我遵循 Apple 示例代码来解决冲突,但在使用(旧)文档和数据存储(不是 iCloud Drive)在 ​​ios8 上进行测试时发现,设置 NSFileVersion 属性 resolved = TRUE 是不够的。 setResolved 有时会失败。

解决方案是在unresolvedConflictVersionsOfItemAtURL 的结果上调用removeAndReturnError。文档说(我的重点): “对于您不再需要的任何版本,请调用 NSFileVersionremoveAndReturnError: 方法来回收文件的存储空间。文档修订保留在服务器上,直到您删除它们。”

for (NSFileVersion *v in [NSFileVersion unresolvedConflictVersionsOfItemAtURL:conflictURL])
        if ([v removeAndReturnError:&error] == NO)
            MRLOGERROR(error);

这似乎解决了这个问题。

请注意,我不会担心 currentVersionOfItemAtURL 在设备之间存在差异。我知道这本质上是任意的,将取决于设备上发生的订单更改。

还请注意,所有冲突解决操作都应包含在文件协调器中:

[[[NSFileCoordinator alloc] initWithFilePresenter:nil]
 coordinateWritingItemAtURL:self.conflictFileName options:0 error:&coordError byAccessor:
 ^(NSURL *conflictURL) 
....
/// resolve conflicts here
....
];

【讨论】:

以上是关于当 URL 报告 NSURLUbiquitousItemHasUnresolvedConflictsKey 为 true 但没有其他版本的 URL 时,这意味着啥?的主要内容,如果未能解决你的问题,请参考以下文章

Azure 负载测试不报告数据驱动的 url

如何将 URL 反射回查询生成器

Crystal Report通过变量传递图像URL时未显示动态图像

发布“永久”cppcheck 报告

获取报告参数作为 URL 字符串

关于詹金斯(Jenkins)产生NAN%的诱人报告,并且报告URL为空