IOS get sandbox file path and write/delete sandbox files

Source: Internet
Author: User

For security reasons, the sandbox mechanism of the iOS system stipulates that each app can access only the files under the current sandbox directory (with exceptions, such as the ability of the system contacts to be accessed by third-party apps under user authorization), a rule that reveals the closeness of the iOS system.

First, a few major directories in the sandbox

Each sandbox has a similar directory structure, as shown (from Apple's official documentation):

The sandbox catalogs for each app are similar, mainly containing the 4 directories shown in the figure:

1, Myapp.app

① Store Content

The directory contains the data for the application itself, including the resource file and executable file. After the program starts, the code or resources are dynamically loaded into memory from the directory as needed, and lazy loading is used here.

② the entire directory is read-only

To prevent tampering, the application will sign the directory when it is installed. In the case of non-jailbreak, the contents of this directory cannot be changed, and if the contents of the directory are changed on the jailbreak device, the corresponding signature will be changed, in which case the result of the Apple website description is that the application will not start and I have not practiced it.

Whether ③ will be synced by itunes

Whether

2. Documents

① Store Content

We can save the application's data file in this directory. However, these data types are limited to non-renewable data, and renewable data files should be stored in the Library/cache directory.

Whether ② will be synced by itunes

Is

3, Documents/inbox

① Store Content

This directory is used to hold files opened by an external application requesting the current application.

For example, our application is called a, several open file formats are registered to the system, B is applied with a file F in a supported format, and application call a opens F. Since F is currently in the sandbox of the B application, we know that the sandbox mechanism is not allowed A to access the files in the B sandbox, so Apple's solution is to speak F copy a copy of the Documents/inbox directory to the A application, and then let a open f.

Whether ② will be synced by itunes

Is

4. Library

① Store Content

Apple is recommended to store default settings or other status information.

Whether ② will be synced by itunes

Yes, but in addition to the caches subdirectory

5, Library/caches

① Store Content

The cache files are mostly cached, which can be stored in the directory by the user during use. As mentioned earlier, the documents directory is used to store non-renewable files, so this directory is used to hold those renewable files, such as data requested by the network. For this reason, the application usually also needs to be responsible for deleting these files.

Whether ② will be synced by itunes

Whether.

6, Library/preferences

① Store Content

The application's preferences file. The settings data we write with Nsuserdefaults will be saved to a plist file in that directory, which is called Write Plist!

Whether ② will be synced by itunes

Is

7. tmp

① Store Content

Various temporary files that save files that are not needed when the app is started again. Moreover, when the application no longer needs these files should be actively deleted, because the contents of the directory can be removed from the system at any time, the current known one possible reason is that the system disk storage space is insufficient.

Whether ② will be synced by itunes

Whether

Get Documents Path

Nsarray*paths=nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask,yes);

Nsstring*path=[paths objectatindex:0];

NSLog (@ "path:%@", Path);

Get the Library Path

Nsarray*paths=nssearchpathfordirectoriesindomains (Nslibrarydirectory,nsuserdomainmask,yes);

Nsstring*path=[paths objectatindex:0];

NSLog (@ "path:%@", Path);

Get caches path

Nsarray*paths=nssearchpathfordirectoriesindomains (Nscachesdirectory,nsuserdomainmask,yes);

Nsstring*path=[paths objectatindex:0];

NSLog (@ "path:%@", Path);

Get the TMP path

Nsstring*tmp=nstemporarydirectory ();

NSLog (@ "tmp:%@", TMP);

IOS get sandbox file path and write/delete sandbox files

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.