When Conflict occur in UIDocument I can get all conflicted version by calling unresolvedConflictVersionsOfItemAtURL:
on NSFileVersion
but how can I get UIDocument (snapshot) of that versions ?
I want to loop all versions and merge it myself.
Updated I have come across this How can I merge conflicted UIDocument's in iCloud? and try to do it this way, but I don't think its correct one because open UIDocument is asynchronous operation. What is the right way to do this ?
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 ;
}
}];
}
}];
Instead of calling openWithCompletionHandler, you want to do something along the lines of:
So swap openWithCompletionHandler with readFromURL and you should be able to access your document right away in order to resolve the conflict.