IOS 5 | How-To Create and Configure an iCloud IOS 5 app
iCloud is one the new features of IOS 5 with a lot of promise and real user payback with the growing number of devices we are all using. iCloud allows a user to share and sync their data from various apps between devices. Basically data is uploaded to servers on the Internet and vice versa downloaded updated locally when a device is connected. Apps can also share data amongst themselves, something that was a bit tricky beforehand.
This tutorial will walk you through the process of setting up iCloud to be used in a document based app and to share a simple document.
Step 1 : Create a Provisioning Profile
Each app that you deploy to a device or the App Store requires a Provisioning Profile, regardless if you want to use iCloud or not. We also need a Provisioning Profile because you can’t test iCloud on the XCode Simulators, you need to deploy to a device: iPad, iPhone or iPod Touch. You also need a Provisioning Profile to enable iCloud.
Navigate to the Apple Developer Portal and click on Member Center. Click on the IOS Provisioning Portal link and click on the App ID tab to setup your app.
Click on the New App ID button. Enter a name for your app following the instructions on the page. For this tutorial, I used quickDox as an app name. Also enter a Bundle identifier; something like com.kevlangdo.quickDox. Click on the Submit button to save the App ID.
At the bottom of the App ID Manage tab you see you app in a grid with thew Push Notifications and Game Center enabled as well as the InApp Purchases enable. To enable iCloud for your app, click on the Configure button under the Action heading.
In the Configure App ID page, enable the iCloud service and click on the Done button to save your changes. That is it for enabling iCloud in the Provisioning Portal.
Next we need a Provisioning Profile proper. The first part of this step was to create an App ID and enable iCloud for that app. Click on the Provisioning tab. Click on the New Profile button, enter a name for the Provisioning Profile like quickDox iCloud Test App; Select a certificate, select the App ID that you set up in the first part of this Step and finally select a device or devices that you will use to test your app. If no device is available, you will need to set one up.
Click the Submit button to save you changes.
Back at the Provisioning Profiles page, under Actions for your new app, a download button will appear after a few minutes. You may need to refresh your page a few times. Download the Provisioning Profile when ready. Double click on the file to add the Provisioning Profile to your XCode Organizer.
Step 2 : Create iCloud Enabled App
Once the Provisioning Profile is created and configure in XCode, it is time to create our app and enable iCloud.
Launch XCode and create a Page-Based application. Give your app the same name as the App ID you created in the IOS Provisioning Portal. Enter the same company identifier as in the IOS Provisioning Portal, add the optional prefix and select Universal for the Device Family. Click Next to create the project.
You will notice that XCode created two storyboards; one for each device type.
Select Project root to open the Targets page. Scroll to the bottom of the page to the Entitlements section. Enable the Entitlements by checking the appropriate checkbox. You will notice that the iCloud key/value pair gets filled in as well as iCloud containers and Access Key fields. You will also notice that a new file with the entitlements extension is created and placed in the project files path.
If you select the file, it will display the Entitlement configuration for your app.
Step 3 : Check for iCloud Availability
To be able to bow out gracefully when the device is not connected or otherwise unavailable, we will add some code to the AppDelegate implementation file in the didFinishLaunchingWithOptions method. So, click on the AppDelegate file, in my project it is kvlAppDelegate.m and add the following code to the didFinishLaunchingWithOptions method:
The URLForUbiquityContainerIdentifier method returns the container associated with the current app. If the iCloud service isn’t available, the application will catch the error and bow out gracefully. Specifying nil as a parameter returns the first container that is configured in the Entitlements file. You could specify a hard coded value here as well as a string for the Container ID.
Step 4: Test the iCloud service
Connect your device to your Mac and when XCode detects its presence, it will appear in the Scheme selector field.
Select the target device and launch the app. It will get deployed to the target device and launch. Open the log console and you will see the following message that iCloud service has accessed the local file system. The daemon transfers file to this directory on your target device. You can retrieve and or place files at this location for syncing.
This is the steps in a nutshell to create the basic iCloud application. In the next tutorial I will show how to actually create documents or files and to sync them with the external iCloud service.
More by this Author
iOS UIPickerView is a versatile UI control in the UIKit of the Cocoa Touch Framework. Learn how to create single and multi-column UIPickerViews with this tutorial.
This Storyboard Connections tutorial provides insight on how to create connection in a Storyboard, set delegates, add code to interact with the different objects. It is designed for new programmers or at least...
Learn to create PDF documents using the APIs in the iOS UIKit. Use the UIGraphicsBeginPDFContextToFile and the UIGraphicsBeginPDFContextToData to quickly create and save PDF files with this sample iOS iPhone app.