Getting Started with iOS network programming: icloud document storage Programming instance

Source: Internet
Author: User
Tags uikit value store

icloud document storage programming is more complex relative to key value data stores, involving customizing document classes, obtaining icloud document catalogs, locating documents in ubiquity containers, saving documents, and resolving document conflicts.

Example: icloud document storage Programming design

Example describes the icloud document storage programming process, the screen has a text box and a button control, in the device 1 input, click the "Save Data" button to save the data icloud server. The right image is a device 2 screen, and after a few seconds the icloud server-side data is read on device 2 and displayed in a text box.

Configure Xcode Engineering

Writing icloud document storage application also requires some configuration in the Xcode project to select Tagets→mynotes→summary→entitlements

In the diagram ubiquity Contrainers adds Com.51work6.mynotes, which is the Ubiquity container identifier, which can have multiple ubiquity container identities that represent different directories. The Com.51work6.mynotes representative directory is as follows:

/var/mobile/library/mobile documents/98z3r5xu29~com~51work6~mynotes/

The 98z3r5xu29 was generated when the iOS developer configured the portal site Creation app ID, which is called the team ID.

If the application does not use the icloud key value data store Key-value store can not be configured.

Custom document Classes

We need to encapsulate a document class, which inherits the abstract class Uidocument, and Uidocument implements the Nsfilepresenter protocol. A class that implements the Nsfilepresenter protocol, which represents files and directories that can be viewed and edited, which are used in conjunction with the file Coordinator class nsfilecoordinator to coordinate the management of files or directories.

This class is named Myclouddocument, and the Myclouddocument code is as follows:

#import <UIKit/UIKit.h> 
     
      
     
@interface Myclouddocument:uidocument① 
     
@property (Strong, nonatomic) nsstring *contents; 
     
@end 
     
      
     
#import "MyCloudDocument.h" 
     
@implementation myclouddocument 
     
      
     
//Loading Data 
     
-(BOOL) loadfromcontents :(ID) Contents OfType: (NSString *) TypeName Error: (nserror * *) Outerror② 
     
{ 
     
if ([contents length] > 0) 
     
{ C11/>self.contents = [[NSString alloc] initwithdata:contents encoding:nsutf8stringencoding]; ③ 
     
} return 
     
YES; 
     
Save Data 
     
-(ID) Contentsfortype: (NSString *) TypeName Error: (nserror * *) Outerror④ 
     
{return 
     
[ Self.contents datausingencoding:nsutf8stringencoding];  ⑤ 
     
} 
     
@end

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.