iOS Sandbox brief Introduction

Source: Internet
Author: User

Let's start with a brief description of what a sandbox is: you can simply understand it as a directory where changes to the directory do not cause any loss to the operating system. (A little introduction here too)

Look at the Apple Sandbox directory:

And a picture of Apple's official picture.

An iOS app is done in its own sandbox.

First of all:

Deveices, inside is a variety of simulator equipment.

Then look for a simulator device. The data inside is inside. Then container inside the data there is a application is the installation software of the device.

We can see that there are a lot of them (even if we reset Content and Settings, there will be.) Because there is the software that comes with the device, such as contacts, maps and so on. )。

Just open one and you can see it. A program consists of three directories:

Documents

Library: Also includes caches and preferences

Temp

One of the

Documents only user-generated files, other data, and files that the program cannot create, the data is automatically backed up through icloud. All of our recorded audio and pictures can be placed here.

Library: Data that can be re-downloaded or regenerated should be stored in the library's caches directory. This is used for cache caching.

TMP: Data that is temporarily used. icloud does not automatically back up these files, which are deleted at any time after use, to avoid occupying user device space.

-(NSString *) documentdirectory {    *paths = Nssearchpathfordirectoriesindomains (nsdocumentdirectory , Nsuserdomainmask, YES);     return [Paths Objectatindex:0];}

The above method can be used to obtain:

/users/zhanggui/library/developer/coresimulator/devices/b6134687-cc10-40de-bd9d-a2e5ad2d5c03/data/containers/ data/application/34361283-8619-481d-b8cb-b25eb4b787e2/documents

That is the path of documents.

You can also get through the following methods:

NSString *s = Nshomedirectory ();

The following results are obtained:

/users/zhanggui/library/developer/coresimulator/devices/b6134687-cc10-40de-bd9d-a2e5ad2d5c03/data/containers/ data/application/08a6d627-1363-48b4-8af8-a1ed361dc9d6

So named Incredibles, we get the directory of the installation software through Nshomedirectory. (It includes documents/library/temp)

Apple's official introduction is to return the user's or application's home directory, depending on the platform.

Take a look at how to get the caches directory path:

  NSString *s = [Nssearchpathfordirectoriesindomains (nscachesdirectory, Nsuserdomainmask, YES) ObjectAtIndex:0 ];

return Result:

/users/zhanggui/library/developer/coresimulator/devices/b6134687-cc10-40de-bd9d-a2e5ad2d5c03/data/containers/ Data/application/db647e93-5f05-4b7b-a8e9-f6f01dd2586b/library/caches

Finally look at how to get the TMP directory:

  NSString *s = Nstemporarydirectory ();

return Result:

/users/zhanggui/library/developer/coresimulator/devices/b6134687-cc10-40de-bd9d-a2e5ad2d5c03/data/containers/ data/application/c7ca833e-8d20-480b-ab91-234a8f17336d/tmp/

--------------------------------------------------------------------probably that much---------------------------------------------- ----------------------

No, no, no, look at Apple's official note:

AppName . App

This is the app ' S 

documents/

Use the This directory to store user-generated content. The contents of this directory can is made available to the user through file sharing; Therefore, his directory is should only contain files, and wish to expose to the user.

The contents of this directory is backed up by ITunes.

documents/inbox

Use the This directory to access files that your app WA s asked to open by outside entities. Specifically, the Mail program places emails attachments associated with your apps in this directory. Document interaction controllers may also place files in it.

Your app can read and delete files in this directory, but cannot create new files or write to existing files. If the user tries to edit a file in this directory, your apps must silently move it out of the directory before making any Changes.

The contents of this directory is backed up by ITunes.

library/

This is the top-level directory for any files of User data files. You typically put files in one of the several standard subdirectories. IOS apps commonly use THE&NBSP, application support  and  Caches   subdirectories; However, you can create custom subdirectories.

Use the  Library,  subdirectories for any files, you don ' t want exposed to the user. Your app should not use these directories for user data files.

The contents of the  Library  directory (with the exception of the  Caches  subdirectory) is backed up by ITunes.

For additional information on the Library directory and its commonly used subdirectories, See the Library Directory Stores app-specific Files.

tmp/

Use the This directory to the write temporary files that does not need to persist between launches of your app. Your app should remove files from the This directory when they is no longer needed; However, the system may purge the If your app is not running.

The contents of this directory is not backed up by ITunes.

The great God of English can look at it. Bad drifting over,,,,

See more: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/ Filesystemprogrammingguide/filesystemoverview/filesystemoverview.html

iOS Sandbox brief Introduction

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.