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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.