Methods for obtaining the paths of documents, tmp, app, and Library, tmpapp

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.