当UIDocument中发生冲突时,我可以通过调用unresolvedConflictVersionsOfItemAtURL:
上的NSFileVersion
来获取所有冲突的版本但是如何获得该版本的UIDocument(快照)?
我想循环所有版本并自己合并。
更新 我遇到过这个How can I merge conflicted UIDocument's in iCloud?并尝试这样做,但我不认为它是正确的,因为打开UIDocument是异步操作。这样做的正确方法是什么?
NSFileVersion *currentVersion = [NSFileVersion currentVersionOfItemAtURL:senderDocument.fileURL];
NSArray *conflictedVersions = [NSFileVersion unresolvedConflictVersionsOfItemAtURL:senderDocument.fileURL];
RecentDocument *currentDocument = [[RecentDocument alloc] initWithFileURL:currentVersion.URL];
[currentDocument openWithCompletionHandler:^(BOOL success) {
if (!success) {
NSLog(@"Failed to open");
return ;
}
for (NSFileVersion *version in conflictedVersions) {
RecentDocument *conflictedDocument = [[RecentDocument alloc] initWithFileURL:version.URL];
[conflictedDocument openWithCompletionHandler:^(BOOL success) {
if (!success) {
NSLog(@"Failed to open");
return ;
}
}];
}
}];
答案 0 :(得分:0)
您不想调用openWithCompletionHandler,而是希望按照以下方式执行操作:
RecentDocument * thisDoc = [[RecentDocument alloc] initWithFileURL:url];
NSError* innerReadError;
[thisDoc readFromURL:url error:&innerReadError];
因此,将openWithCompletionHandler与readFromURL交换,您应该能够立即访问您的文档以解决冲突。