Each iOS program has its own sandbox (sandbox), and iOS8 is available after the sandbox is partially open
We can access the folders under the sandbox
Folders include:
1,documents: Saving data that needs to be persisted when the app runs
2.tem: Save temporary data, system restart automatically disappears
3.library: Stored program default settings and other information
4.library/caches: Saving Temporary files
5.library/preferences: Save preferences configuration information, SQLite data
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
Get root directory
NSString *dir=nshomedirectory ();
NSLog (@ "%@" dir);//mac under:/users/tang,ios is not this
Documents Path
First parameter: The name of the sandbox folder to get
Second parameter://nsuserdomainmask = 1,//User home directory Nslocaldomainmask = 2,//current Machine Nsnetworkdomainmask = 4,//visible Host in the network Nssystemdomainmask = 8,//system directory, non-modifiable (/system) Nsalldomainsmask = 0x0ffff,//all
Third parameter: yes/no whether to get the full path YES
nsarray* Arr=nssearchpathfordirectoriesindomains (nsdocumentdirectory, 1, YES);
NSLog (@ "%@", [arr objectatindex:0]);
Caches path
Arr=nssearchpathfordirectoriesindomains (nscachesdirectory,1, YES);
NSLog (@ "%@", [arr objectatindex:0]);
Library Path
Arr=nssearchpathfordirectoriesindomains (nslibrarydirectory, 1, YES);
NSLog (@ "%@", [arr objectatindex:0]);
TEM path
NSString *tem=nstemporarydirectory ();
To apply, create a file:
The Preferences folder under the library path cannot be accessed, only the stitching string
Arr=nssearchpathfordirectoriesindomains (nslibrarydirectory, 1, YES);
NSLog (@ "%@", [arr objectatindex:0]);
NSString *path1= [[arr objectatindex:0] stringbyappendingpathextension:@ "Preferences/1.txt"];
NSString *[email protected] "write files, record data";
[Data writetofile:path1 Atomically:yes encoding:nsutf8stringencoding Error:nil];
}
return 0;
}
Basic operational summary of the iOS sandbox mechanism