Sandbox: Every iOS app creates a file system directory for itself, a separate, closed, secure space called a sandbox
Sandbox is a security system
Features: 1. The range of activities for each application is limited to its own sandbox.
2. You can't go across your sandbox to access content in another application sandbox (IOS8 is already partially open)
3. Applications requesting or accepting data out-of-date require permission authentication
The application's sandbox directory will have three folders Documents, Library (caches and preferences directories below), TMP
Document: Save data that needs to be persisted when the app is run itunes automatically backs up the directory
get the Document directory
nsarray *path = nssearchpathfordirectoriesindomains(nsdocumentdirectory, Nsuserdomainmask, YES);
NSLog(@ "%@", path);
nsstring *documentdirectory = [path objectatindex:0];
NSLog(@ "%@", documentdirectory);
// get tmp directory: Save the temporary data required by the application to run, and then drop the corresponding files from the directory to delete, there is no runtime, the system may also clear the directory files, itunes will not sync the directory
nsstring *tmpdir = nstemporarydirectory();
NSLog(@ "%@", TmpDir);
Library: Default settings and other status information for stored programs
// get Library directory
nsarray *paths = nssearchpathfordirectoriesindomains(nslibrarydirectory, Nsuserdomainmask, YES);
nsstring *pathlib = [Paths objectatindex:0 ];
NSLog(@ "%@", pathlib);
// get library/caches directory: Store cache files
nsarray *path1 = nssearchpathfordirectoriesindomains(nscachesdirectory, Nsuserdomainmask, YES);
nsstring *pathcaches = [path1 objectatindex:0];
NSLog(@ "%@", pathcaches);
// get library/preferences directory: Save all your app's preferences
nsarray *path2 = nssearchpathfordirectoriesindomains(nslibrarydirectory, Nsuserdomainmask, YES);
nsstring *pathpre = [[path2 objectatindex:0] stringbyappendingpathcomponent :@ "Preferences"];
NSLog(@ "%@", Pathpre);
// Get the package path for the application
nsstring *imagepath = [nsbundle mainbundle]. ResourcePath;
NSLog(@ "%@", ImagePath);
// string object to write to file
// construct string Object
nsstring *strpath = [documentdirectory stringbyappendingstring:@ "/text.txt"];
// construct string Object
nsstring *foo_str = @ "This is a test";
// string storage
[Foo_str writetofile: strpath atomically:YES encoding:nsutf8stringencoding error:nil];
// read string object from File
nsstring *str = [nsstring stringwithcontentsoffile: strpath encoding: Nsutf8stringencoding error:nil];
NSLog(@ "%@", str);
// Array Object write file
// construct the storage path of the array object
nsstring *arraypath = [documentdirectory stringbyappendingstring:@ "/array.plist"];
// construct array Object
nsarray *foo_array = @[@ "Hjp", @ "hly", @ "LCL"];
// Store array Objects
[Foo_array writetofile: Arraypath atomically:YES];
nsarray *reultarray = [nsarray arraywithcontentsoffile: Arraypath];
NSLog(@ "%@", Reultarray);
Writing and reading of sandboxed and simple Objects (preview)