2

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.

Ross
  • 145
  • 1
  • 12

1 Answers1

1

You should observe the UIDocumentStateChangedNotification. If the documentState property of your document has the UIDocumentStateInConflict flag set, there is a conflict. Note that a document can be in multiple states simultaneously, so don't check with ==, instead use something like if (document.state & UIDocumentStateInConflict) {....

You can then get the conflicting versions with the otherVersionsOfItemAtURL: class method of NSFileVersion.

You can find more detailed information in the chapter on resolving document conflicts in the Document-Based App Programming Guide for iOS.

omz
  • 53,243
  • 5
  • 129
  • 141