Cover by Vandad Nahavandipoor

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

19.7. Handling Conflicts in iCloud Documents

Problem

You want to be able to solve conflicts between two or more versions of a document (managed through UIDocument) in iCloud.

Solution

Use the otherVersionsOfItemAtURL: class method of the NSFileVersion class to detect different versions of the current revision of the document you are managing using an instance of UIDocument. Each version of a document is of type NSFileVersion. The procedure to take is as follows:

  1. Instantiate and open a document.

  2. Listen for UIDocumentStateChangedNotification notifications (see Recipe 19.6).

  3. Check if the documentState property of the document that caused the aforementioned notification to be fired has the UIDocumentStateInConflict state. If yes, then we will proceed to the next step. If not, we will handle the issue in a different way.

Note

When a conflict occurs in a document, iCloud will automatically attempt to resolve that conflict by either merging two or more revisions of that document together, or simply taking the latest version. Whatever iCloud does, it will give you a revision of the document to work with. This revision is called the current version of that document.

  1. We will use the currentVersionOfItemAtURL: class method of the NSFileVersion class to get the current version of the document by passing the URL of the document to this method.

  2. Next, we will use the otherVersionsOfItemAtURL: class method of the NSFileVersion class to get all other versions of the document, by passing the URL of the document ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required