iOS sandbox (sandbox) mechanism and get sandbox path

Source: Internet
Author: User

One, each iOS Application SDK is limited in the sandbox, the sandbox is equivalent to a folder with only the owner visible permissions, Apple has the following restrictions on the sandbox.

(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), there are three folders in the root directory of the sandbox:

Documents: The application's data files should generally be stored in this folder for storing user data or other information that should be backed up regularly.

Library: There are two folders, caches store application to start the required information (cache files, etc.), preferences contains the application preferences file, but do not modify the preferences here.

Temp: Holds temporary files, that is, the app starts the unwanted files again.

Second, get the sandbox path

(1), there are several ways to get the sandbox root directory:

A. Get with Nshomedirectory

1 nsstring *path = nshomedirectory (); 2 NSLog (@ "path =%@", Path);

b, using the user name to obtain

1 nsstring *username = Nsusername (); // gets the name of the user who created the application 2 nsstring *rootpath = nshomedirectoryforuser (userName); 3 NSLog (@ "rootpath =%@", RootPath);

C. Get Documents Path

1 nsstring *documentpath = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) Objectatindex:0]; 2 nsstring *filepath = [documentpath stringbyappendingstring:@ "data.plist"]; // add files to documents 3 NSLog (@ "filePath =%@", FilePath);

D. Get the temp path

1 nsstring *temppath = Nstemporarydirectory (); // Get temp directory, if write data inside, when program exits will empty 2 NSLog (@ "temppath =%@", TempPath);

E. Get caches path

1 nsarray *paths = nssearchpathfordirectoriesindomains (nscachesdirectory, Nsuserdomainmask, YES); 2 nsstring *cachespath = [paths Objectatindex:0]; 3 NSLog (@ "cachespath =%@", Cachespath);

iOS sandbox (sandbox) mechanism and get sandbox path

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.