OS sandbox mechanism and OS sandbox Mechanism

Source: Internet
Author: User

OS sandbox mechanism and OS sandbox Mechanism

/*

IOS sandbox mechanism. Applications can only access files in their app directories.

Unlike android, iOS does not have an SD card and cannot directly access images, videos, and other content.
Content generated by iOS apps, such as files and cached content, must be stored in your sandbox.
By default, each sandbox contains three folders: Documents, Library, and tmp. The Library contains the Caches and Preferences directories.
The complete path above is: User-> resource library-> Application Support-> iPhone Simulator-> 7.1-> Aplications
 
Documents: Apple recommends that you store the files created by the program and the file data generated by application browsing in this directory. This directory will be included during iTunes backup and recovery.
Library: the default setting of the storage program or other status information;
Library/Caches: stores cached files and stores the persistent data of applications. It is used for data storage after an application upgrade or application is disabled and won't be synchronized by itunes. Therefore, to reduce the synchronization time, you can consider putting some large files that do not need to be backed up into this directory.
Tmp: provides a place to create temporary files in real time, but does not need to be persisted. After the application is closed, the data in this directory will be deleted, or the system may clear the data when the program is not running.
*/
# Import "NSFileManagerViewController. h"

@ Interface NSFileManagerViewController ()

@ End

@ Implementation NSFileManagerViewController

-(Id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil
{
Self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
If (self ){
// Custom initialization
}
Return self;
}

-(Void) viewDidLoad
{
[Super viewDidLoad];

// Obtain the sandbox directory
NSString * dirHome = NSHomeDirectory ();
NSLog (@ "APP_home: % @", dirHome );

[Self dirDoc];
[Self dirLib];
[Self dirCache];
[Self dirTmp];
[Self createDir];
[Self createFile];
[Self redFile];
[Self fileAttriutes];
[Self deleteFile];
}

// Obtain the Document directory path
-(NSString *) dirDoc {
// [NSHomeDirectory () stringByAppendingPathComponent: @ "events"];
NSArray * path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
NSString * documentsDirectory = [path objectAtIndex: 0];
NSLog (@ "app_home_doc: % @", documentsDirectory );
Return documentsDirectory;
}

-(Void) dirLib {
// [NSHomeDirectory () stringByAppendingPathComponent: @ "Library"];
NSArray * path = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSUserDomainMask, YES );
NSString * libraryDirectory = [path objectAtIndex: 0];
NSLog (@ "app_home_lib: % @", libraryDirectory );
}

-(Void) dirCache {
NSArray * cacPath = NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES );
NSString * cachePath = [cacPath objectAtIndex: 0];
NSLog (@ "app_home_lib: % @", cachePath );
}

-(Void) dirTmp {
// [NSHomeDirectory () stringByAppendingPathComponent: @ "tmp"];
NSString * tmpDirectory = NSTemporaryDirectory ();
NSLog (@ "app_home_tmp: % @", tmpDirectory );
}

// Wear folder
-(Void) createDir {
NSString * documentsPAth = [self dirDoc];
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * testDirectory = [documentsPAth stringByAppendingString: @ "test"];
// Create a directory
BOOL res = [fileManager createDirectoryAtPath: testDirectory
WithIntermediateDirectories: YES
Attributes: nil
Error: nil];
If (res)
{
NSLog (@ "folder created successfully ");
}
Else
{
NSLog (@ "Folder creation failed ");
}
}

// Create a file
-(Void) createFile {
NSString * documentPath = [self dirDoc];
NSString * testDirectory = [documentPath stringByAppendingPathComponent: @ "test"];
NSFileManager * filemanager = [NSFileManager defaultManager];
NSString * testPath = [testDirectory stringByAppendingPathComponent: @ "test.txt"];
BOOL res = [filemanager createFileAtPath: testPath contents: nil attributes: nil];
If (res ){
NSLog (@ "File Created successfully: % @", testPath );
} Else {
NSLog (@ "file creation failed ");
}
}
-(Void) writeFile {
NSString * documentsPath = [self dirDoc];
NSString * testDirectory = [documentsPath stringByAppendingPathComponent: @ "test"];
NSString * testPath = [testDirectory stringByAppendingPathComponent: @ "test.txt"];
NSString * content = @ "Test Written content! ";
BOOL res = [content writeToFile: testPath atomically: YES encoding: NSUTF8StringEncoding error: nil];
If (res ){
NSLog (@ "file written successfully ");
} Else
NSLog (@ "file write failed ");
}

// Read the file
-(Void) redFile
{
NSString * documentsPath = [self dirDoc];
NSString * testDirectory = [documentsPath stringByAppendingPathComponent: @ "test"];
NSString * testPath = [testDirectory stringByAppendingPathComponent: @ "test.txt"];
// NSData * data = [NSData dataWithContentsOfFile: testPath];
// NSLog (@ "File Read succeeded: % @", [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]);
NSString * content = [NSString stringWithContentsOfFile: testPath encoding: NSUTF8StringEncoding error: nil];
NSLog (@ "File Read succeeded: % @", content );
}

// File attributes
-(Void) fileAttriutes {
NSString * documentsPath = [self dirDoc];
NSString * testDirectory = [documentsPath stringByAppendingPathComponent: @ "test"];
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * testPath = [testDirectory stringByAppendingPathComponent: @ "test.txt"];
NSDictionary * fileAttributes = [fileManager attributesOfItemAtPath: testPath error: nil];
NSArray * keys;
Id key, value;
Keys = [fileAttributes allKeys];
Int count = [keys count];
For (int I = 0; I <count; I ++)
{
Key = [keys objectAtIndex: I];
Value = [fileAttributes objectForKey: key];
NSLog (@ "Key: % @ for value: % @", key, value );
}
}
// Delete an object
-(Void) deleteFile {
NSString * documentsPath = [self dirDoc];
NSString * testDirectory = [documentsPath stringByAppendingPathComponent: @ "test"];
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * testPath = [testDirectory stringByAppendingPathComponent: @ "test.txt"];
BOOL res = [fileManager removeItemAtPath: testPath error: nil];
If (res ){
NSLog (@ "File deleted ");
} Else
NSLog (@ "file deletion failed ");
NSLog (@ "does the file exist: % @", [fileManager isExecutableFileAtPath: testPath]? @ "YES": @ "NO ");
}



Why is there the conclusion that "windows systems are getting slower and slower to use, but mac OS is not like this? What is the authenticity of this conclusion?

Any system that has been used for a long time will get slower and slower, but it will take longer for the system to slow down.
From this perspective, Windows is slower than Mac OS.
 
After jailbreak, does the iOS sandbox for IPA become invalid?

Yes. The biggest advantage of the sandbox mechanism is:
1. You cannot run any local (other) executable program.
2. You cannot read any information from the local file system or write any information to the file system.
3. You cannot view any information about the local computer except Java version information and a few harmLess operating system details.
4. In particular, the code in the sandbox cannot view private information such as user name and email address.

Some malicious pirated applications may have backdoor programs to steal user privacy information. For security reasons, it is not recommended to jailbreak.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.