I use iCloud to sync an user xml file between devices in my apps, with a UIDocument subclass, similar to the code from the question:http://stackoverflow.com/questions/7795629/icloud-basics-and-code-sample. but I am not sure when and how should I detect a conflict. I read the sdk doc and searched the internet but didn’t seem to find any information with detailed information. it seems we can use some code like
NSNumber* conflicted ;
[url getResourceValue:&conflicted forKey:NSURLUbiquitousItemHasUnresolvedConflictsKey error:nil];
but in my app, it seems always give a true value for “conflicted”?
also I am not sure when should I detect the conflict, my guess is before the contentsForType method of the UIDocument subclass is called. if anyone can give any hint that would be great.
You should observe the
UIDocumentStateChangedNotification. If thedocumentStateproperty of your document has theUIDocumentStateInConflictflag set, there is a conflict. Note that a document can be in multiple states simultaneously, so don’t check with==, instead use something likeif (document.state & UIDocumentStateInConflict) {....You can then get the conflicting versions with the
otherVersionsOfItemAtURL:class method ofNSFileVersion.You can find more detailed information in the chapter on resolving document conflicts in the Document-Based App Programming Guide for iOS.