Getting Started with iOS network programming: Resolving document conflict issues in icloud document stored procedures

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.