I've spent some days now trying to find, or figure out for myself, how to programmatically merge UIDocument changes when the notification UIDocumentStateChangedNotification fires and the document's state has UIDocumentStateInConflict set.
All the examples that I can find (Apples, Ray Wenderlich's etc etc) all detail the prompt user to select a version method. I can't find any that demostrate the correct way to programmatically merge. This worries me as it makes me think it's too erratic to trust and is generally avoided as a solution? My experience with it so far strengthens that position.
Let me detail each problematic area in my attempts.
1) What is the correct way to read the current document contents and the NSFileVersion conflict versions for the purpose of a merge? Using anything with a completion block is really messy in syncing. UIDocument's openWithCompletionHandler: isn't tempting to use. In fact, as a rule, what is the recommended way to read-only a UIDocument? Why open a document just for reading? I've tried using UIDocument's readFromURL: which is fine for the current document but if I try to use it on any of the NSFileVersion's conflict versions it reads the current version, not the version at the URL (I've used MacOS terminal to dig deep into the ../data/.DocumentRevisions-V100/PerUID/... files to confirm this.). For the conflict versions the only way it works for me is to directly read access those files. (e.g. NSData initWithContentsOfFile:)
2) Once past the reading in of the variations of the file, and having managed to merge, how does one correctly save the merge? This one is really not documented anywhere I can find. The only approach I've succeeded with is by re-using one of the NSFileVersion's conflict files, overwriting it, and then using UIDocument's replaceItemAtURL: to make it current. I have also attempted to use UIDocument's revertToContentsOfURL: after using the replaceItemAtURL: but it just crashes with no reason given. Since the merge appears to work fine without it I'm not worried but thought I'd include this as a detail.
3) The iPhone/iPad Simulator (V10.0) doesn't notify of conflicts until I relaunch the app. Is that to be expected or am I doing something wrong? I ask because under the simulator's Debug menu there's Trigger iCloud Sync which syncs but the conflicts don't get flagged until the next app re-boot. Is this just a limitation of the simulator?
Thanks,