IOS sandbox introduction, ios sandbox
First, let's briefly introduce what a sandbox is: you can simply understand it as a directory. modifications to this directory will not cause any loss to the operating system. (Here is a little introduction)
Look at Apple's sandbox directory:
Add an official Apple Image
An iOS app is operated in its own sandbox.
First:
Deveices, which contains various simulator devices.
Find a simulator device. The data in it is the data in it. Then, an Application in the Data in the Container is the installation software of the device.
We can see that there are many (even if we Reset Content and Settings, there will also be. Because there are software that comes with the device, such as address book and map .).
Open a program at will and you will see that a program contains three directories:
Documents
Library: including Caches and Preferences
Temp
The
Only user-generated files, other data, and files that cannot be created by Program Programs are supported. The data here is automatically backed up through iCloud. You can put the recorded audio and photo images here.
Library: the data that can be re-downloaded or re-generated should be saved in the caches directory of the Library. This is used to store the cache.
Tmp: temporary data. ICloud does not automatically back up these files, and the data should be deleted at any time after use to avoid occupying User device space.
- (NSString *)documentDirectory { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [paths objectAtIndex:0];}
Through the above method, we can get:
/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/34361283-8619-481D-B8CB-B25EB4B787E2/Documents
That is, the paths of Documents.
You can also obtain the following method:
NSString *s = NSHomeDirectory();
The following result is displayed:
/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/08A6D627-1363-48B4-8AF8-A1ED361DC9D6
Therefore, we obtained the directory for installing the software through NSHomeDirectory. (This includes Documents/Library/temp)
What Apple officially introduced is to return the Home Directory of the user or application, depending on the platform.
Let's take a look at how to obtain the Caches directory path:
NSString *s = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Returned results:
/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/DB647E93-5F05-4B7B-A8E9-F6F01DD2586B/Library/Caches
Finally, let's take a look at how to get the tmp directory:
NSString *s = NSTemporaryDirectory();
Returned results:
/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/C7CA833E-8D20-480B-AB91-234A8F17336D/tmp/
---------------------------------------------------------------------- So many --------------------------------------------------------------------
NO, NO, NO. Let's take a look at Apple's official instructions:
AppName.app |
This is the app's bundle. This directory contains the app and all of its resources. You cannot write to this directory. to prevent tampering, the bundle directory is signed at installation time. writing to this directory changes the signature and prevents your app from launching. you can, however, gain read-only access to any resources stored in the apps bundle. for more information, seeResource Programming Guide The contents of this directory are not backed up by iTunes. However, iTunes does perform an initial sync of any apps purchased from the App Store. |
Documents/
|
Use this directory to store user-generated content. the contents of this directory can be made available to the user through file sharing; therefore, his directory shoshould only contain files that you may wish to expose to the user. The contents of this directory are backed up by iTunes. |
Documents/Inbox
|
Use this directory to access files that your app was asked to open by outside entities. specifically, the Mail program places email attachments associated with your app 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 app must silently move it out of the directory before making any changes. The contents of this directory are backed up by iTunes. |
Library/
|
This is the top-level directory for any files that are not user data files. You typically put files in one of several standard subdirectories. iOS apps commonly useApplication Support AndCaches Subdirectories; however, you can create M subdirectories. UseLibrary Subdirectories for any files you don't have want exposed to the user. Your app shocould not use these directories for user data files. The contents ofLibrary Directory (with the exception ofCaches Subdirectory) are backed up by iTunes. For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files. |
tmp/
|
Use this directory to write temporary files that do not need to persist between launches of your app. your app shocould remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running. The contents of this directory are not backed up by iTunes. |
Take a look. Not good ,,,,
For more information, see https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html.