App Sandbox for iOS development

Source: Internet
Author: User

1 , Application Sandbox overview

Each iOS app has its own app sandbox (the app sandbox is the file system directory) and is isolated from other file systems. The app must stay in its own sandbox, and other apps won't be able to access the sandbox.

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

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

/users/apple/library/application Support/iphone simulator/6.0/

Applications

"Notes" By default, the emulator directory is hidden, to be displayed, you need to enter the following command on the Mac Terminal:

command to display Mac hidden files: Defaults write Com.apple.finder appleshowallfiles YES.

command to hide Mac hidden files: Defaults write Com.apple.finder appleshowallfiles NO.

After you lose, click Enter, exit the terminal, and restart the finder.

Restart Finder: Mouse click the Apple flag in the upper-left corner of the window and force exit-->finder--> restart.

2 , application sandbox structure analysis

The application Package : (the layer in) contains all the resource files and executables.

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 the 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 that is typically stored in large volumes and does not require backup.

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

Summarize:

1. Large size (itunes does not back up)

(1) TMP (the contents may be randomly cleared by the system)

(2) Library/caches

2. Small size (itunes will back up)

(1) Documents

(2) Library/preference

3 , the common way to get the sandboxed catalog

get the Sandbox root directory :

NSString *home = nshomedirectory();

Get Documents:(2 ways ):

( 1 ) using the sandbox root mosaic "Documents" string

NSString *home = nshomedirectory();

NSString *documents =

[Home stringbyappendingpathcomponent: @ "Documents"];

Where the stringbyappendingpathcomponent method can be directly before Documents to spell the slash.

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

( 2 ) using Nssearchpathfordirectoriesindomains function:

Nsuserdomainmask represents from the user folder, 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];

Get tmp:

NSString *tmp = nstemporarydirectory();

Get library/caches : ( 2 ways similar to Documents ) :

(1) Stitching the "Caches" string with the sandbox root.

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

library/preference:

Access the settings information under this directory through the Nsuserdefaults class.

App Sandbox for iOS development

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.