iCloud Implementation in iOS 7

iCloud lets you access your music, photos, documents, and more from all your devices. iCloud backs up data of  all your iOS devices. Now you can access that data from any of your device.

 

Screen Shot 2013-11-11 at 7.11.32 PM

 

Here I would like to  tell  how we can use iCloud for storing information through our app. In iphone device, as we know we have user defaults. We can store any information in user defaults from our app. But here is a problem, that information will be limited to that device only.

iCloud plays an important role where  We can store our information on iCloud , then that information can be accessed from user’s all devices.

steps for  implementing iCloud in your app.

Creating App ID

For using iCloud functionalities in your, you need to enable iCloud in your App id. Here are the steps:-

1. Go to apple developer site. Open your app id.

2. Click on Edit button.

Screen Shot 2013-11-12 at 10.08.46 AM

3. Now enable iCloud.

Screen Shot 2013-11-12 at 10.09.22 AM

4. Now click on DONE at the bottom.

Screen Shot 2013-11-12 at 10.11.33 AM

5. Create profile for this updated app id.

Enable Entitlements

1. Now open your project in xCode. Click on project. Click on targets. Choose Capabilities.

Screen Shot 2013-11-12 at 10.43.53 AM

 

2. Now click on switch OFF at the right of iCloud.

Screen Shot 2013-11-12 at 10.44.16 AM   Screen Shot 2013-11-12 at 12.12.21 PM

3. Now click on Add

Screen Shot 2013-11-12 at 10.44.33 AM

 

4. Enter your developer account details. Now You will be logged in from your account. Click on Choose . It will autofill the details for your app id .

Screen Shot 2013-11-12 at 12.12.21 PM

5. Now click on Key-Value Store checkbox.

Screen Shot 2013-11-12 at 12.12.45 PM

 

It will automatically create entitlement file iCloudDemo.entitlements . Now you can start coding.

 

Checking iCloud Availability

For using iCloud , you should first check iCloud availability to ignore crashes and inconsistent data .

NSURL *ubiquityContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiquityContainer) {
    NSLog(@"iCloud access at %@", ubiquityContainer);
    // Access document here... 
} else {
    NSLog(@"No iCloud access");
}

If you pass in nil to the method , it will automatically returns the first iCloud Container set up for the project. You can pass identifier also.

Using Key Value Store

Now you have the access to iCloud. Now you can access document on iCloud , iCloud is having  many ways of storing information. But here is the simplest way to store basic information on iCloud. iCloud is having a Key Value Store where we can store values in dictionary format.

Here is the code to store the value on iCloud.

[[NSUbiquitousKeyValueStore defaultStore] setObject:@"YES" forKey:@"alreadyUsedTheApp"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];

Here boolean value YES will be saved for key  “alreadyUsedTheApp” . You need to synchronize   the  NSUbiquitousKeyValueStore to reflect the changes on iCloud.

Here is the code to retrieve the value from iCloud.

[[NSUbiquitousKeyValueStore defaultStore] stringForKey:@"alreadyUsedTheApp"];

Now you know how to store and retrieve value in iCloud. You can start playing with your code according to your requirement.

 

The following two tabs change content below.

Submit a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current month ye@r day *