Programmatically resolve NSDocument iCloud version conflicts?

509 views Asked by At

I have a Mac "Shoebox" app that internally uses NSDocument objects, but does not expose the concept of individual documents to the user. (I rely on NSDocument to make syncing via iCloud easier.)

My problem is that when a version conflict arises, my app shows the default NSDocument conflict resolution alert (see below) letting the user pick one or two winners.

In the concept of my app this doesn't make sense. Is there a way to intercept/prevent that alert and handle the conflict programmatically?

I know that I can detect version conflicts with the code below. However, I still need to prevent the alert sheet.

[NSFileVersion unresolvedConflictVersionsOfItemAtURL:document.fileURL];

Example conflict resolution alert:

Example conflict resolution alert

3

There are 3 answers

0
ImHuntingWabbits On BEST ANSWER

This is the built in behavior of NSDocument when it discovers there are unresolved version conflicts. If you do not wish to use it you'll have to drop support for NSDocument and use a lower level abstraction like NSFileManager + NSFileVersion.

0
malhal On

See the doc Resolving Document Version Conflicts

Strategies for Resolving Document Version Conflicts

Your application can follow one of three strategies for resolving document-version conflicts:

  • Merge the changes from the conflicting versions.
  • Choose one of the document versions based on some pertinent factor, such as the version with the latest modification date.
  • Enable the user to view conflicting versions of a document and select the one to use.

Which strategy is best to use depends a lot upon your document data. If you can merge the contents of different document versions without introducing contradictory elements, then follow that strategy. Or choose the document version with the latest modification date if your application doesn’t suffer any loss of data as a result.

Generally, you should try to resolve the conflict without involving the user, but for some applications that might not be possible. If an application takes the user-centered approach, it should discreetly inform the user about the version conflict and expose a button or other control that initiates the resolution procedure. An Example: Letting the User Pick the Version examines the code of an application that lets the user select the document version to use.

0
berbie On

You can override + (BOOL)usesUbiquitousStorage and return NO. This will no longer show the ubiquity conflict panel.