iOS Program sandbox directory structure analysis catalog get

Source: Internet
Author: User

Each iOS app has its own app sandbox (the app sandbox is the file system directory) and is isolated from other file systems. Apps must stay in their sandbox, other apps can't access the sandbox

Apply the sandbox's file system directory as shown (assuming the name of the app is called network)

The root path of the emulator app sandbox is: (Apple is the user name, 7.1 is the emulator version)

/users/apple/library/application Support/iphone simulator/7.1/applications

Application Package: (the network in) contains all the resource files and executable files

Documents: Saves data that needs to be persisted when the app runs, and it backs up the directory when itunes synchronizes the device. For example, a game app can save a game archive in that directory

tmp: Saves the temporary data required to run the app, and then deletes the corresponding file from the directory when it is finished. When the app is not running, the system may also purge files in that directory. itunes does not back up this directory when syncing the device

library/caches: Saves data that needs to be persisted when the app runs, and itunes syncs the device without backing up the directory. Non-critical data with large storage volumes and no backup required

library/preference: Save all your app's preferences, and the iOS settings (settings) app will find the app's settings in that directory. This directory is backed up when itunes syncs the device

Common ways to get a sandboxed catalog:

Sandbox root directory: nsstring *home = nshomedirectory();

Documents: (2 ways)

Stitching the "Documents" string with the sandbox root

NSString *home = nshomedirectory();

NSString *documents = [Home stringbyappendingpathcomponent: @ "documents"];

Not recommended because a new version of the operating system may modify the directory name

Using the Nssearchpathfordirectoriesindomains function

Nsuserdomainmask representative from the user folder to find

YES represents the wavy character "~" in the expanded path

Nsarray *array = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, NO);

In iOS, only one directory matches the parameters passed in, so there is only one element in the collection

NSString *documents = [array objectatindex:0];

tmp: nsstring *tmp = nstemporarydirectory();

library/caches: (2 ways similar to documents)

Stitching the "Caches" string with the sandbox root

Use the Nssearchpathfordirectoriesindomains function (change the function's 2nd parameter to: nscachesdirectory)

library/preference: Access to Settings information in this directory through the Nsuserdefaults class

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.