views:

18

answers:

2

My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?

EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.

-Ash

+1  A: 

You include it as a file in the Resources folder of your application.

Claus Broch
Will that ensure it ends up in the Documents area when the program is installed? I want to allow people to take backups of their database.
Ash
No, your application will have to copy the default database when it detects that this doesn't exist in the documents area.
Claus Broch
+1  A: 

Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.

A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.

Dan Ray
Good idea! I don't know why I was expecting there to be some kind of official, automated method for this.
Ash