17.6. Managing the State of Documents in iCloud


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


Stat listening to the UIDocumentStateChangedNotification notification.


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.


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:


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


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.


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 ...

Get iOS 5 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.