"iOS Dev-3" sandbox introduction and how to get the path of the files in the sandbox, image import method and image path to get

Source: Internet
Author: User

In fact, each app is a separate folder, each app is independent of each other, so their folders are also independent, this folder is a sandbox. Sandbox benefits, security. Disadvantage, it is more difficult for programs to share data with each other.

(1) How do I find the sandbox source file for my application?

The general sandbox source files are stored in the ~/library/application support/iphone simulator/version number/applications/folder, but the library (Chinese name Repository) folder is hidden. So you need a way to click in: In the Finder, press cmd+shift+g, then go to the box to enter ~/library, that is, to go directly, rather than by clicking to go.

Of course, you can always use the terminal CD in, note that some directory name has two words in front of the middle space to add \ Escape, such as CD./library/application\ support/iphone\ simulator/

After selecting the simulated version, and then into the application, which is the application, of course, is named with a hash code, there are 4 files:

Documents, libraries, TMP and HELLO.APP, which hold permanent and temporary data, are the main files in each sandbox.


(2) How to get the file path inside the sandbox with code?

Note: NSBundle is a way to get the resources inside the. App file.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//    Get the entire program directory NSString *homepath=nshomedirectory ();    NSLog (@ "%@", HomePath);    Get the. App file directory NSString *apppath=[[nsbundle Mainbundle]bundlepath];    NSLog (@ "%@", AppPath);    Documents directory Nsarray *arr1=nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES);    NSLog (@ "%@", [arr1 objectatindex:0]);    Library directory Nsarray *arr2=nssearchpathfordirectoriesindomains (nslibrarydirectory, Nsuserdomainmask, YES);    NSLog (@ "%@", [arr2 objectatindex:0]);    Caches directory, under the library Nsarray *arr3=nssearchpathfordirectoriesindomains (nscachesdirectory, Nsuserdomainmask, YES);    NSLog (@ "%@", [Arr3 objectatindex:0]);    TMP directory NSString *tmppath=nstemporarydirectory ();    NSLog (@ "%@", Tmppath);    Use the entire program directory with TMP to put together the TMP directory, other directories can be completed nsstring *tmppath_1=[homepath stringbyappendingpathcomponent:@ "tmp"];    NSLog (@ "%@", tmppath_1); Override Point For customization after application launch. return YES;}
Results:

2014-09-23 21:05:58.966 hello[7763:546804]/users/andy/library/developer/coresimulator/devices/ 64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/data/application/ 08972b0f-5ecf-42b2-934b-892e8e3f7f6d2014-09-23 21:05:58.966 hello[7763:546804]/Users/Andy/Library/Developer/ coresimulator/devices/64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/bundle/application/ e7d6885c-9cc1-461d-867c-8d0da5af183a/hello.app2014-09-23 21:05:58.967 hello[7763:546804]/Users/Andy/Library/ developer/coresimulator/devices/64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/data/application/ 08972b0f-5ecf-42b2-934b-892e8e3f7f6d/documents2014-09-23 21:05:58.967 hello[7763:546804]/Users/Andy/Library/ developer/coresimulator/devices/64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/data/application/ 08972b0f-5ecf-42b2-934b-892e8e3f7f6d/library2014-09-23 21:05:58.967 hello[7763:546804]/Users/Andy/Library/ developer/coresimulator/devices/64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/data/application/08972b0f-5ecf-42b2-934b-892e8e3f7f6d/library/caches2014-09-23 21:05:58.967 hello[7763:546804]/Users/Andy/Library/ developer/coresimulator/devices/64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/data/application/ 08972b0f-5ecf-42b2-934b-892e8e3f7f6d/tmp/2014-09-23 21:05:58.967 hello[7763:546804]/Users/Andy/Library/Developer /coresimulator/devices/64eda842-5b0c-448d-bf2b-b063d09b60cb/data/containers/data/application/ 08972b0f-5ecf-42b2-934b-892e8e3f7f6d/tmp

(3) How to import pictures and how to get the path

There are two ways to import an IMG folder or a picture into a program: creat groups and Creat folder reference, The former indicates that the imported images are in the. App (which is actually the Brother folder), the IMG folder listed on the left is only used for grouping instead of the real directory, while the latter means not only importing the images, but also importing the IMG directory, i.e., the app has an IMG folder, which is stored in the image.



We see the following to get the image path is used nsbundle, in fact, because it is in the. App folder, and NSBundle is to get the resources in the app, so in the enhanced memory again.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Create groups way, pictures directly in the. App, the following two ways the same    nsstring *path1=[[nsbundle mainbundle]pathforresource:@ "1" oftype:@ "PNG" ];    NSString *path2=[[nsbundle mainbundle]pathforresource:@ "1.png" oftype:nil];    NSLog (@ "%@,%@", path1,path2);        Create folder reference mode, Picture in IMG, the following three ways the same    nsstring *path3=[[nsbundle mainbundle]pathforresource:@ "1" OfType: @ "PNG" indirectory:@ "IMG"];    NSString *path4=[[nsbundle mainbundle]pathforresource:@ "1.png" Oftype:nil indirectory:@ "img"];    NSString *path5=[[nsbundle mainbundle]pathforresource:@ "Img/1.png" Oftype:nil Indirectory:nil];    NSLog (@ "%@,%@,%@", path3,path4,path5);    Override point for customization after application launch.    return YES;}


iOS Development-3 sandbox sandbox introduction and how to get the path of each file in the sandbox, image import method and picture path get

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.