Methods for obtaining the paths of documents, tmp, app, and Library, tmpapp
The phone Sandbox Model contains four folders: documents, tmp, app, and Library.
1,
DocumentsYou should write all application data files to this directory. This directory is used to store user data or other information that should be regularly backed up.
2,
AppName. appThis is the application package directory, including the application itself. Because the application must be signed, you cannot modify the content in this directory during runtime. Otherwise, the application may fail to start.
3,
Library (including
Caches and Preferences)
Preferences:Preference files that contain applications. Instead of directly creating a preference file, you should use the NSUserDefaults class to obtain and set the preference of the application.
Caches:It is used to store application-specific support files and save the information required when the application is restarted.
4,
TmpThis directory is used to store temporary files and save the information that is not required when the application starts up again.
To obtain these directory paths:
1. Obtain the home directory path function:
NSString * homeDir = NSHomeDirectory ();
2. How to obtain the paths of the Documents directory:
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
NSString * docDir = [paths objectAtIndex: 0];
3. How to obtain the Caches directory path:
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES );
NSString * cachesDir = [paths objectAtIndex: 0];
4. Obtain the tmp directory path:
NSString * tmpDir = NSTemporaryDirectory ();
5. How to obtain the path of Chinese source files in the application package:
For example, you can obtain an image resource (apple.png) path in the program package:
NSString * imagePath = [[NSBundle mainBundle] pathForResource: @ "apple" 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.