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:
UIDocumentStateNormalThings are normal and no conflicts have occurred in the document.
UIDocumentStateClosedThis 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.
UIDocumentStateInConflictThis 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access