icloud documents inevitably clash during the preservation process, we must have a strategy to resolve the conflict. The adoption of policies depends on the needs of the user, some simple and complex, the simplest of which is to overwrite the conflicting version directly with the current version. Complex policies, such as: If the two text file conflict, you can list two conflicting points, let the user to judge and then save.
The strategy we use is to overwrite the previous version with the current version. Resolving conflicts first requires registering uidocumentstatechangednotification notifications in the Updateubiquitousdocuments: method:
//(void) Updateubiquitousdocuments: (nsnotification *) Notification {... if the file in icloud changes _myclouddocument) {//Register Clouddocument object to document coordinator, document status changes to receive notification [Nsfilecoordinator addfilepresenter:_myclouddocum ENT];
①//Registration Document status change notification [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (resolveconflict:) Name:uidocumentstatechangednotification Object:nil]; ②}//Document conflict resolution-(void) ResolveConflict: (nsnotification *) Notification {if (_myclouddoc
Ument && _myclouddocument.documentstate = = uidocumentstateinconflict) {③nslog (@ "conflict occurs");
Document conflict resolution policy Nserror *error; if (![ Nsfileversion Removeotherversionsofitematurl: _ Myclouddocument.fileurl Error:&error]) {④nslog (@) to remove other
Documents:%@ ", [Error Localizedfailurereason]);
Return } _myclouddocument.contents = _txtcontent.text; ⑤[_myclouddocumentUpdatechangecount:uidocumentchangedone]; ⑥} [[Nsnotificationcenter Defaultcenter] removeobserver:self name:uidocumentstatechangednotification Object:nil]; ⑦//the Clouddocument object from the document coordinator [Nsfilecoordinator Removefilepresenter:_myclouddocument]; ⑧}
This article is from the "Dongsheng" blog, please be sure to keep this source http://2009315319.blog.51cto.com/701759/1193879