IOS network programming-solves document conflicts in the Process of iCloud document storage

Source: Internet
Author: User

There will inevitably be conflicts in the process of saving the iCloud documents. We must have a set of conflict resolution policies. Policy adoption depends on user needs. Some of them are simple and complicated. The simplest is to directly use the current version to overwrite conflicting versions. Complex policies: for example, if two text files conflict, you can list the two conflict points for the user to determine and save them.

 

Our policy is to use the current version to overwrite previous versions. To resolve the conflict, you must first register the uidocumentstatechangednotification notification in the updateubiquitousdocuments: method:

// Call-(void) updateubiquitousdocuments (nsnotification *) Notification {...... If (_ myclouddocument) {// register the clouddocument object to the document coordinator. Only when the document status changes can you receive the notification [nsfilecoordinator addfilepresenter: _ myclouddocument]; ① // notification of registration document status change [[nsnotificationcenter defacenter center] addobserver: Self selector: @ selector (resolveconflict :) name: uidocumentstatechangednotification object: Nil]; ②} // file conflict resolution-(void) resolveconflict :( nsnotification *) Notification {If (_ myclouddocument & _myclouddocument.doc umentstate = uido Cumentstateinconflict) {③ nslog (@ "conflict occurred"); // document Conflict Resolution Policy nserror * error; If (! [Nsfileversion removeotherversionsofitematurl: _ myclouddocument. fileurl error: & error]) {④ nslog (@ "remove other documents: % @", [error localizedfailurereason]); Return ;}_ myclouddocument. contents = _ txtcontent. text; ⑤ [_ myclouddocument updatechangecount: uidocumentchangedone]; ⑥} [[nsicationicationcenter defacenter center] removeobserver: selfname: uidocumentstatechangednotification object: Nil]; 7. // remove the clouddocument object [nsfilecoordinator removefilepresenter: _ myclouddocument]; identifier} from the document coordinator}

 

 

From IOS network programming and cloud application best practices: Guan Dongsheng @ Tony _ Guan Dongsheng

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.