我使用 iCloud 在应用程序中的设备之间同步用户 xml 文件,并使用 UIDocument 子类,类似于问题中的代码:http://stackoverflow.com/questions/7795629/icloud-basics-and-code -样本。但我不确定何时以及如何检测冲突。我阅读了sdk文档并在互联网上搜索但似乎没有找到任何详细信息。看来我们可以使用一些代码,例如 NSNumber* 冲突; [url getResourceValue:&conflicted forKey:NSURLUbiquitousItemHasUnresolvedConflictsKey 错误:nil];
但在我的应用程序中,它似乎总是给出“冲突”的真实值? 我也不确定何时应该检测到冲突,我的猜测是在调用 UIDocument 子类的contentsForType 方法之前。如果有人能给出任何提示,那就太好了。
最佳答案
您应该观察UIDocumentStateChangedNotification
。如果文档的 documentState
属性设置了 UIDocumentStateInConflict
标志,则存在冲突。请注意,文档可以同时处于多个状态,因此不要使用 ==
检查,而是使用类似 if (document.state & UIDocumentStateInConflict) {...
.
然后,您可以使用 NSFileVersion
的 otherVersionsOfItemAtURL:
类方法获取冲突版本。
您可以在chapter on resolving document conflicts中找到更多详细信息在 Document-Based App Programming Guide for iOS .
关于iphone - 何时以及如何检测 iCloud 冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9568183/