A lot of articles have written this question, I just to record, lest always turn the book ...
1. Documents directory: You should write all the application data files to this directory. This directory is used to store user data or other information that should be backed up regularly.
2. Library directory: There are two sub-directories under this directory: Caches and Preferences
Preferences directory: Contains the application's preferences file. Instead of creating a preference file directly, you should use the Nsuserdefaults class to get and set your application's preferences.
Caches directory: Used to hold application-specific support files, saving the information that is needed during application startup.
3. tmp directory: This directory is used to store temporary files, saving information that is not needed during the application restart.
4. Appname.app directory (that is, the directory mentioned in the previous blog ): This is the application's package directory, which contains the application itself. Because the application must be signed, you cannot modify the contents of this directory at run time , which may cause the application to fail to start.
Ways to get these directory paths:
- function to get the home directory path:
NSString *homedir = Nshomedirectory ();
- Ways to get the documents directory path:
Nsarray *paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES);
NSString *docdir = [Paths objectatindex:0];
- To get the caches directory path:
Nsarray *paths = nssearchpathfordirectoriesindomains (nscachesdirectory, Nsuserdomainmask, YES);
NSString *cachesdir = [Paths objectatindex:0];
- method to get the TMP directory path:
NSString *tmpdir = nstemporarydirectory();
- To obtain the path to the resource file in the application package:
For example, get a picture resource (headpic.png) path in the package by:
NSString *imagepath = [[NSBundle mainbundle] pathforresource:@ "headpic" oftype:@ "PNG"];
UIImage *appleimage = [[UIImage alloc] initwithcontentsoffile:imagepath];
The Mainbundle class method in the code is used to return an object that represents the application package.
ios--How to get the file directory