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. Each application is within its own sandbox
2. You can't go across your sandbox to access the contents of another application sandbox
3. Applications requesting or receiving data outside the application require permission authentication
Ways to show and hide folders:
command to display Mac hidden files: Defaults write Com.apple.finder appleshowallfiles-bool true
command to hide Mac hidden files: Defaults write Com.apple.finder Appleshowallfiles-bool false
Then restart the Finder, tap the apple logo in the upper left corner of the screen-force quit-Select Finder and click Restart, this time you can reopen the Finder to see the hidden files.
The content path in the simulator is as follows:
Each application has its own unique directory:
/var/mobile/applications/uuid
When the application is installed, the UUID is randomly generated;
The catalog is rebuilt when the removal application is reinstalled
There are several folders under each app directory:
documents/
library/
Library/caches
Library/preferences
tmp/
. App
The functions of each file (folder) are as follows:
. app/, this is a running application file, with a signed package, including application code and static data;
documents/
: Use the This directory to store critical user documents and app data files. Critical data is any data that cannot being recreated by your app, such as user-generated content.
The contents of this directory can is made available to the user through file sharing. The contents of this directory is backed up by ITunes.
: Apple recommends that file data created in the program or browsed in the program be saved in this directory, which is included in itunes backup and restore;
library/
: This directory was the top-level directory for files, which is not user data files. You typically put files in one of the several standard subdirectories and you can also create custom subdirectories for files You want backed up and not exposed to the user. You should don't use this directory for user data files.
The contents of this directory (with the exception of the Caches subdirectory) is backed up by ITunes.
For additional information on the library directory, see "The Library directory Stores app-specific Files."
: Application support files;
library/preferences/: The default settings or other status information of the stored program;
library/caches/: Store cached files, itunes does not back up this directory, files in this directory will not be removed from the app, and the contents will be deleted when the system cleans up disk space.
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 it determines they is no longer needed. (The system may also purge lingering files from this directory when your apps are not running.)
In IOS 2.1 and later, the contents of this directory is not backed up by ITunes.
: Where temporary files are created and stored, the application starts successfully and the temporary file does not need to be persisted.
Note:
itunes backs up all documents and library files while syncing with the iphone.
When the iphone restarts, all of the TMP files are discarded.
Here's the code to get the file directory and read and write the file: sample Demo free: http://download.csdn.net/detail/weasleyqi/7508141
To get the root directory:
NSString *homepath = Nshomedirectory (); NSLog (@ "Home directory:%@", HomePath);
Get the Document directory:
Nsarray *docpath = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES); NSString *documentspath = [DocPath objectatindex:0];
Get the Library directory:
Nsarray *libspath = Nssearchpathfordirectoriesindomains (Nslibrarydirectory, Nsuserdomainmask, YES); NSString *libpath = [Libspath objectatindex:0];
Get the Cache directory:
Nsarray *cacpath = Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES); NSString *cachepath = [Cacpath objectatindex:0];
Get the TMP directory:
NSString *temppath = Nstemporarydirectory (); NSLog (@ "Temp directory:%@", TempPath);
Write file:
Nsarray *docpath = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES); NSString *documentspath = [DocPath objectatindex:0]; Write to File if (!documentspath) { NSLog (@ "directory not Found"); } else { NSString *filepaht = [Documentspath stringbyappendingpathcomponent:@ "test.txt"]; Nsarray *array = [Nsarray arraywithobjects:@ "Title", @ "Contents", nil]; [Array writetofile:filepaht atomically:yes]; }
Read file:
Nsarray *docpath = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES); NSString *documentspath = [DocPath objectatindex:0]; NSString *readpath = [Documentspath stringbyappendingpathcomponent:@ "test.txt"]; Nsarray *filecontent = [[Nsarray alloc] initwithcontentsoffile:readpath]; NSLog (@ "File contents:%@", filecontent);
Example demo:http://download.csdn.net/detail/weasleyqi/7508141