Sandbox (sandbox)

Source: Internet
Author: User

The iOS sandbox mechanism sandbox is a separate storage area used by the system to save non-code files.  So all non-code files are to be saved in this, examples like, icons, sounds, images, attribute lists, text files, etc. 1.1, each application has its own storage space 1.2, the application can not turn over their walls to access the contents of other storage space 1.3, the application request data must pass permission detection, if not meet the conditions, will not be released.Documents: Saves data that needs to be persisted when the app runs, and it backs up the directory when itunes synchronizes the device. For example, a game app can save a game archive in that directory.Temp: Saves the temporary data that is required to run the app, and then deletes the corresponding file from the directory when it is finished. When the app is not running, the system may also purge files in that directory.itunes does not back up the directory when syncing the device.library/caches: Saves data that needs to be persisted when the app runs, and itunes syncs the device without backing up the directory. General storage volume, non-critical data that does not need to be backed up.library/preference: Save all your app's preferences, and the iOS setting (settings) app will find the app's settings in that directory. The directory is backed up when itunes synchronizes the device Second, the Code implementation#import"ViewController.h"

@interfaceViewcontroller()

@end

@implementationViewcontroller

- (void) Viewdidload {
[SuperViewdidload];

NSString*path =Nshomedirectory// get sandbox path-find sandbox storage space     nslog@ "--%@" ,path) ;   //Find the Sandbox path--1,2
Nsarray*paths =Nssearchpathfordirectoriesindomains(NSDocumentDirectory,Nsuserdomainmask,YES);//PassSearchFind the path collection of the sandbox
NSLog(@ "==>%@", paths);

NSString*dpath = [pathstringByAppendingPathComponent:@ "TMP"];//Through the path stitching method of string, find the sandbox path--(sandbox has3 a path through a string of three paths, you can find these three paths)
    nslog@ "dpath:%@"     // Remove documents path NSString Firstobject     nslog@ "------%@" ,documentPat h);
nsstring *str = @ " Hello girl "; NSString*txtpath = [pathstringByAppendingPathComponent:@ "1.txt"];
[StrWriteToFile: Txtpathatomically:YESEncoding:Nsutf8stringencodingError:nil]; writes a string to 1.txt, if there is no such file, the system will first create, then write, overwrite the original file if it already exists   //    //To write a picture into a sandbox, you first need to convert the image to data
UIImage *image = [UIImage imagenamed:@ "1.jpg"];
//NSData *data = uiimagejpegrepresentation (image, 1);
//[Data Writetofile:[dpath stringbyappendingstring:@ "/1.jpg"] atomically:yes];// if using stringbyappendingstring Stitching Path, you need to add the file in front of }

Sandbox (sandbox)

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.