Question

I have been puzzling about retrofitting my app for iCloud for a few days and hope someone can help. After getting past code signing issues I am not sure I understand the model for incorporating iCloud. I'll tell you the problem I'm trying to solve first since I'm a big believer in telling people what I'm trying to do before having them try to fix the way I'm doing it :-)

My app workflow

  1. User browses the store which lists a series of training plans they can download
  2. User picks a plan and downloads it
  3. I pull the training plan from our webserver customized to their needs
  4. I add the filename for the training plan they downloaded to a plist of plans they own
  5. User opens the training plan and sees the day-to-day schedule

I want the user to be able to do this on their iPhone and then open their iPad and see the exact same training plans synced over there.

My problem I currently save the files to the Documents directory and that works just fine. How do I retrofit this to work with iCloud such that folks without iCloud enabled can continue to use the app but those who do get the added benefit?

My understanding I'm confused as to whether I still need to save to Documents folder and then save a copy to the iCloud folder OR whether I just write to the iCloud folder from now on.

If it's the former I believe I just write a copy the Documents folder files to the iCloud area too to push it up but how do I detect a new file in the iCloud folder and copy it back to my Documents folder?

If it's the latter the files should just exist right?

I'm hoping it's the latter and that still supports devices without iCloud turned on...

Thanks for any help clarifying.

Adam

Was it helpful?

Solution

The iCloud API is pretty well documented and there is a specific chapter that deals with what you are after:

Managing the Life Cycle of a Document

A document goes through a typical life cycle. A document-based application is responsible for managing its progress through that cycle. As you can see from the following list, most of these life-cycle events are initiated by the user:

  1. The user first creates a document.
  2. The user opens an existing document and the application displays it in the document’s view or views.
  3. The user edits the document. A user may ask to put a document in iCloud storage or may request the removal of a document from iCloud storage.
  4. During editing, saving, or other actions, errors or conflicts can happen; the application should learn about these errors and conflicts and either attempt to handle them or inform the user.
  5. The user closes a selected document. The user deletes an existing document. The following sections discuss the procedures a document-based application must complete for these life-cycle operations.

In essence, you application is responsible for working out whether iCloud is available for a particular user and then confirm that the user wants to store their data in the cloud. Based on that selection you will need to work out how to move their existing data from the documents directory to a cloud URL.

On other devices that are setup to use iCloud storage, you have the option to discover documents available via a metadata query.

http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/ManageDocumentLifeCycle/ManageDocumentLifeCycle.html#//apple_ref/doc/uid/TP40011149-CH4-SW1

OTHER TIPS

If you are looking for a very easy sample which implements iCloud, have a look at this:

iCloud basics and code sample

This gives you a concrete example of how to implement some of the stages Rog has cited in his post above. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top