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

17.6. Managing the State of Documents in iCloud

Problem

You want to be able to detect conflicts and other issues that could occur as a result of syncing documents to iCloud.

Solution

Stat listening to the UIDocumentStateChangedNotification notification.

Note

I highly recommend reading Recipe 17.5 before proceeding with this recipe, as the material described here highly relies on what was taught in that section.

Discussion

The UIDocumentStateChangedNotification notification gets sent when the state of an iCloud document (of type UIDocument) is changed. The object carried by this notification is the instance of the UIDocument whose state was changed. You can listen to this notification and then analyze the documentState property of your iCloud document; this property is of type UIDocumentState and can be a mixture of these values:

UIDocumentStateNormal

Things are normal and no conflicts have occurred in the document.

UIDocumentStateClosed

This means that the document has not yet been opened, or was open and has just been closed. You might want to disallow the user from editing the document while the document is in this state. Apple recommends that you do not display alert views to your users, but instead, perhaps, display graphical components on the screen to indicate to the user that editing has been disabled.

UIDocumentStateInConflict

This state indicates that a conflict has happened in the document. For instance, the same document could had been edited by two or more people at the same time ...

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