iOS sandbox is really simple (essence version)

Source: Internet
Author: User

As an iOS developer, there are times when you need to understand some of the underlying things to make progress, so share the sandbox storage of iOS you often face today.

The first thing to understand is what is a sandbox?

An application in iOS can only read files in the file system created for the program, not anywhere else, and this area is called a sandbox, so all non-code files are stored in this, examples like, icons, sounds, images, attribute lists, text files, etc.

For example, let's go to the bank to do the rules, and the Bank also need security protection, will not let you casually disorderly enter. When you need access to something, he will give you a specific area where you can access your stuff, and everyone must obey its rules and regulations.

So this particular area is what, is the sandbox Bai, open the sandbox's main directory method said two, can

Method One:

nsstring *path =nshomedirectory(); // Sand Box

NSLog(@ "nshomedirectory:%@ I am the Sandbox master directory", path);

Method Two:

nsstring *username =nsusername(); // Sand Box

nsstring *rootpath =nshomedirectoryforuser(userName);

NSLog(@ "nshomedirectoryforuser:%@ I am the Sandbox master directory ", RootPath);

The main contents of the sandbox are also loaded with other things, like the vaults in the bank's coffers, which store different things separately.

First of all, introduce the first Application, It is the program document directory, do not store things, you can not go to

Here's the point (i.e. you can go to the sub-vault):  

document,library the caches and preferences,tmp below.



Document: Generally store files that need to be persisted, itunes will automatically back up this directory, files such as the program set up or browse to the file data (anyway do not want it to disappear or important to put here)

Caches in the library: refers to the cache, that is, when the program is running temporary data, such as the picture you browse, video,itunes does not back up this directory, the application is not running, it may be cleared, the memory is not enough to be erased (anyway, the volume is large, Need to temporarily persist the data, unimportant things, than tablets, videos, these downloaded from the Internet and put here .

Preference in the library: refers to your preferences,itunes automatically backs up this directory, it stores some preferences (such as user name, password, font size, night mode, etc.)

TMP: As the name implies, it is the data that holds temporary files,itunes does not back up this directory, the app does not run, the app will be cleared after exiting.

Summary: It takes a long time to persist the storage of things placed in the Document, not important, but large-sized to the library, the last temporary useless to the TMP (they are the importance of our programmers in descending order).

iOS sandbox is really simple (essence version)

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.