开发者

How do i test my app data persistence during development?

My question is related to the following three questions.

  1. iPhone What happens to previous data when app is upgraded to new version

  2. How the application upgrade works in iPhone

  3. Preventing erasure of user data while upgrading iOS 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.


  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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜