views:

48

answers:

3

Hi,

My question is related to the following three questions.

  1. http://stackoverflow.com/questions/2099747/iphone-what-happens-to-previous-data-when-app-is-upgraded-to-new-version

  2. http://stackoverflow.com/questions/1223696/how-the-application-upgrade-works-in-iphone

  3. http://stackoverflow.com/questions/941479/upgrading-iphone-application-via-itunes

Here are my 2 questions.

  1. Am I supposed to create a "Documents" directory manually on filesystem or create just a "group" in xcode, so that when app is upgraded, data stay persistant?

  2. How I can test the app persistance during the app development on simulator or on IPhone?

Thanks.

A: 

When the app is upgraded your Documents folder is left intact. You can copy files into the Documents directory the first time your app is run such as a sqlite file for example, obviously only if it doesn't already exist. If you use CoreData then it will automatically store your data there. You will need to be able to run migration scripts if your data schema changes on upgrade, so keep that in mind. CoreData has migration features to take care of this for you and of course you can do it manually too.

When you run an app in the simulator it also leaves the Documents directory intact, so you have to delete the app from the simulator to simulate a fresh install. An upgrade is simulated simply by running your code since the Documents folder was created on the 'fresh install' first run.

Ben
My real question is not this. Real question is how/where should I make the document directory?
itsaboutcode
+1  A: 
  1. Neither. The Documents directory is created for you when your app is installed. You can get the path to it using:

    NSString *docuDir = nil;
    NSArray *list = NSSearchPathForDirectoriesInDomains(
            NSDocumentsDirectory, NSUserDomainMask, YES/*expand tilde*/);
    if ([list count]) docuDir = [list objectAtIndex:0U];
    
  2. As @Ben said, the directory is only deleted when you explicitly uninstall the app (delete it from within Springboard). When you build and run, Xcode effectively does an in-place upgrade of your app. If everything is intact then (and there's no reason it wouldn't be), you should be fine.

Jeremy W. Sherman
But how i put my DB or Persistance file into the Documents folder?
itsaboutcode
Use `-[NSFileManager copyItemAtPath:toPath:error:]` or have whatever data type is holding your DB or other file write itself to disk at a path under the Documents directory. If you want a lengthier answer, you should ask that as another question.
Jeremy W. Sherman
A: 

Another way to approach this would be look at the Documents folder. If you are running your app in the simulator, then your app's Documents folder will have a path something like this:

/Users/itsaboutcode/Library/Application Support/iPhone Simulator/4.1/Applications/SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP/

If you are testing on an iDevice, then use Xcode's Organizer window's Summary tab. At the bottom there's a section called Applications. You app will be near the top of that list and it will have a toggle triangle - which you will click on. This will reveal "Application Data" which can be downloaded by clicking on downward pointing arrow to the right.

The iPhone Simulator has the advantage that the Documents folder and its contents can be modified at will. The Application Data on iDevice is read-only (except, of course, for your app at runtime).

westsider