IOS learning notes for 25th days (Introduction to iOS sandbox mechanism), ios sandbox
Knowledge points of iOS Learning (oc language)
I. Introduction to iOS sandbox Mechanism
1) concept: Every ios app has its own sandbox. the sandbox is the directory of the file system, which is isolated from other apps in the file system, and cannot be accessed by the ios system.
Application sandbox of other applications, but it is already open for access (extension) in ios8)
2) extension is a new extended mechanism for ios8 to expand several fixed system regions. It can make up for the communication restrictions of ios sandbox mechanism on applications to a certain extent.
3) The application sandbox generally contains the following file directories:
1. application package: contains all resource files and executable files
2. Documents: stores the persistent data generated during application running. iTunes automatically backs up the directory.
3. tmp: Save the temporary data required when the application is running. After the application is used, delete the corresponding files from this directory. When the application is not running, the system may also automatically clean up the files.
Files in this directory, which is not synchronized by iTunes, will be lost when the iPhone restarts.
4. Libaray: the default setting and other status information of the storage program. iTunes automatically backs up the directory.
5. Libaray/Caches: stores cached files. iTunes does not back up this directory. files in this directory are not deleted after the application exits. Generally, the storage volume is large,
Not a very important resource
6. Libaray/Preferences: save all the preference Settings of the app. the ios Settings app searches for the app Settings in this directory,
ITunes automatically backs up the directory.
4) obtain the root directory of the application, for example:
1 NSString *sandBox=NSHomeDirectory();
5) obtain the Documents directory of the application, for example:
1 // returns the absolute path 2 // NSSearchPathForDirectoriesInDomains (whether the directory to be searched is the user's main directory, YES/NO whether to obtain the full path); 3 NSArray * arry = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); 4 NSLog (@ "% @", [arry lastObject]);
6) obtain the Libaray directory of the application, for example:
1 NSArray *arry2= NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);2 NSLog(@"%@",[arry2 lastObject]);
7) obtain the application's Caches directory, for example:
1 NSArray *arry3= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, 2 NSUserDomainMask, YES);3 NSLog(@"%@",[arry3 lastObject]);
8) obtain the Preferences directory of an application. You cannot directly obtain the Preferences directory. You can only splice the Preferences by yourself. For example:
1 NSArray *arry4= NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);2 NSString *path=[arry4 lastObject];3 path=[path stringByAppendingPathComponent:@"Preferences"];4 NSLog(@"%@",path);
9) obtain the tmp directory of the application, for example:
1 NSString *tmp=NSTemporaryDirectory();2 NSLog(@"%@",tmp);
10) write the file to the specified application directory, for example:
1 NSArray *arry4= NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);2 NSString *path=[arry4 lastObject]; 3 path=[path stringByAppendingPathComponent:@"Preferences/Test.txt"];4 NSString *str=@"abcdefg";5 [str writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];