Basic operational summary of the iOS sandbox mechanism

Source: Internet
Author: User

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

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.