iOS applications have a limited number of directories available for writing content, the design intent is to ensure application security. This post will give a quick run down of the folder locations available in an iOS application and their intended use.
Documents Directory – ApplicationHome/Documents
The Documents directory is the primary location to save user and application related content. This directory and its subdirectories, are backed up when a user does a sync with iTunes. This is directory is also the repository for iTunes file sharing content.
The code below shows how to check for and print the path to the Document directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([paths count] > 0) NSLog(@"Documents directory: %@", [paths objectAtIndex:0] );
Documents Inbox – ApplicationHome/Documents/Inbox
The Documents Inbox is primarily used when an application such as the Mail app calls your app with a request to open a specific file type.
For example, in the post Register File Types to Associate File Extension with an App I wrote an example to demonstrate how to open a file attachment in an application. The file passed to the application (from the Mail Inbox) is stored in the Documents Inbox directory.
The content in the Documents Inbox directory is backed up when a device is synced with iTunes.
tmp – ApplicationHome/tmp
As the name implies, the tmp directory is available for files that are used only while your application running. A good practice would be to remove any files that you create here (before exiting your app). iOS may also clean this directory, however, this is not guaranteed.
The content in the tmp directory is not backed up when a device is synced with iTunes.
Library – ApplicationHome/Library
The Library directory is for intended for content that is not user generated. For example, if you have data that is read into your application at app startup, this would be a good place to store such information.
The content in the Library directory is backed up when a device is synced with iTunes, with one exception, there is a Caches directory that is not backed up.