iOS sandbox mechanism and access to the sandbox directory path

Source: Internet
Author: User

The sandbox mechanism (sandbox) in iOS is a security system that specifies that an application can only read files within a folder created for the app and cannot access content elsewhere. All non-code files are saved in this place, such as slices, sounds, attribute lists, and text files.

(1), the application can operate in its own sandbox, but cannot access any other application's sandbox.

(2), data cannot be shared between applications, files in the sandbox cannot be copied to other application folders, and files in other application folders cannot be copied into the sandbox.

(3), Apple prohibits any read and write files outside the sandbox, and prohibits the application from writing content to a folder other than the sandbox.

(4), the application requests or receives the data outside the request to pass the permission authentication.

To apply the Sandbox directory:

Application Bundle: Contains the application executable and all resource files, read-only.

document/stores data that is generated by the application runtime and that needs to be saved. Back up the directory when itunes or icloud syncs your device.

Library/caches/stores data that is generated by the application runtime and that needs to be saved. itunes or icloud is out of sync.

Library/preferences/Store preference settings. The iOS Preferences (settings) app also looks for app settings in that directory. Nsuserdefaults is saved in this directory. Back up the directory when itunes or icloud syncs your device.

temp/the temporary data that is required to store the application while it is running. When an app is not running, the iOS system may erase files in that directory. However, this automatic purge mechanism should not be relied upon and should be cleaned up in time.

1. How to get the sandbox root directory

NSString *homedir = Nshomedirectory ();

2. Get the document Path

Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);

NSString *docdir = [Paths objectatindex:0];

3. Get caches path

Nsarray *paths = Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES);

NSString *cachesdir = [Paths objectatindex:0];

4. Get the TMP path

NSString *tmpdir = Nstemporarydirectory ();

5, get other paths can refer to http://my.oschina.net/meilidashijie/blog/99837

6, access to resources files can refer to http://my.oschina.net/meilidashijie/blog/99837, to be supplemented.

Nssearchpathfordirectoriesindomains has 3 arguments and the latter two incoming fixed values (in iOS). This function originates from Mac OS X, and in Mac OS X you can pass in other values for the latter two parameters. The first parameter is a constant of type nssearchpathdirectory, specifying the type of directory. Some constants cannot be used in iOS (not available in iOS).

The Nssearchpathfordirectoriesindomains return value is Nsarray instead of nsstring. Because you may get multiple compliant results in Mac Os X. There are only 1 results in iOS, so the resulting array is labeled 0.

iOS sandbox mechanism and access to the sandbox directory path

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.