What does it mean when a URL reports true for NSURLUbiquitousItemHasUnresolvedConflictsKey but there are no other versions of the URL?

311 views Asked by At

In order to test conflicts, I've been saving two different versions of the same document on two devices. On both devices I would then be able to look at the currentVersionOfItemAtURL to see the 'winning' version - which was the same on both devices - and the otherVersionsOfItemAtURL or removeOtherVersionsOfItemAtURL to see the others.

However I now seem to have got a document in a weird state, where currentVersionOfItemAtURL is different on the two devices, and there are no otherVersionsOfItemAtURL or removeOtherVersionsOfItemAtURL. Using getResourceValue:forKey: with NSURLUbiquitousItemHasUnresolvedConflictsKey reports that the URL has unresolved conflicts, but I've no way of seeing them.

What does it mean when a URL reports true for NSURLUbiquitousItemHasUnresolvedConflictsKey but there are no other versions of the URL? Is this a case I need to handle in a production app?

1

There are 1 answers

0
MichaelR On

I followed the Apple sample code for resolving conflicts, but discovered when testing on iOS8 with the (old) Documents and Data store (not iCloud Drive) that setting the NSFileVersion property resolved = TRUE was not sufficient. setResolved would sometimes fail.

The solution was to call removeAndReturnError on the result on unresolvedConflictVersionsOfItemAtURL. The documentation says (my emphasis): "For any versions you no longer need, call the removeAndReturnError: method of NSFileVersion to reclaim the storage for the file. Document revisions remain on the server until you delete them."

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

This seems to have resolved that problem.

Note I wouldn't be concerned that currentVersionOfItemAtURL differed between devices. I understand it is essentially arbitrary and will depend on the order changes occurred on the device.

Also note that all the conflict resolution actions should be wrapped inside a file coordinator:

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