O'Reilly logo

iOS 6 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required