iOS learning iOS sandbox (sandbox) mechanism and file operations (i)

Source: Internet
Author: User

1. iOS sandbox mechanism

iOS apps can only read files in the file system created for the program, and not be able to go anywhere else, this area is a sandbox, so all non-code files are saved in this, image, icon, sound, images, attribute list, text file, etc.

1.1. Each application has its own storage space
1.2, the application can not turn over their walls to access the content of other storage space
1.3, the application requests the data to pass the permission to detect, if does not meet the condition, will not be released.
Through this diagram can only be understood from the surface of the sandbox is a security system, the entire operation of the application through the system to run, the core content is: Sandbox applications to run a variety of operation permissions restrictions.

2. Open the emulator sandbox folder

Here's a look at where the emulator's sandbox folder is on your Mac computer.

The files are in a hidden folder under the personal User name folder, the Chinese is called the Repository, and his folder is in fact the library.

2.1 Method 1, be able to set the display hidden files, and then open directly under the Finder. To set up a way to view hidden files, for example: Open terminal, enter name

command to display Mac hidden files: defaults write com . Apple . Finder appleshowallfiles - bool true

command to hide Mac hidden files: Defaults write Appleshowallfiles-bool false

After you lose, click Enter, exit the terminal, and start the Finder again.
Restart Finder: Mouse click the Apple flag in the upper-left corner of the form and force exit-->finder-->

Now you can see the repository folder.

Locate the/application Support/iphone simulator/folder after opening the repository. This is the sandbox folder for the emulator's various programs.

2.2 Method 2, such a method is more convenient, on the Finder point-to go to the folder, enter the/users/username/library/application support/iphone simulator/to.

Username here to write your user name.

3. Folder structure

By default, each sandbox contains 3 folders: Documents, Library, and TMP. Application can only read and write files in several folders due to the sandbox mechanism applied
Documents: Apple recommends that file data that is created in the program or browsed in the program be saved in this folder, which is included iniTunes backup and restore
Library: The default settings or other status information for the stored program;

library/caches: Store cached files,ITunes does not back up this folder, files under this folder will not be deleted in app exit

TMP: Provides a place to instantly create temporary files.

itunes backs up all documents and library files while syncing with the iphone.

When the iphone restarts, it discards all of the TMP files.

We create a Iossandbox project to expand the practice of sandbox and file read and write operations.

After creation, locate the appropriate folder on the emulator,

This is the full-spread of the folder.

Here are the three folders mentioned above: Documents, Library, tmp

The following article describes folder path fetching and file operations

Sample code: Https://

Copyright statement: This article by, welcome reprint share. Please respect the author's labor, reproduced when the statement and the author of the blog link, thank you

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: 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.