码迷,mamicode.com
首页 > 数据库 > 详细

Sandbox沙盒

时间:2016-03-06 22:06:27      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

一、Sandbox沙盒特点:

         1、应用程序之间相互隔离;

         2、应用程序只能访问自己本地的内容,不能访问其他app文件目录结构(越狱手机除外);

         3、为应用程序构建一个完整的运行空间;

         4、应用程序有自己的缓存和数据备份。

 

二、沙盒目录结构:

          1、Documnets;

           2、HellWord.app

           3、Library;

           4、Tmp;

三、app所在沙盒Sandbox目录:

       模拟器:

            ~/Library/Application Support/iPhone Simulator/6.0/Applications/8F08C873-76C7-406F-AEAD-B499137787DD

         真机:

           /var/mobile/Applications/8F08C873-76C7-406F-AEAD-B499137787DD

四、获取App Home目录

      获取Home目录:

                 NSString *homeDirectory = NSHomeDirectory();

          结果类似:

                ~/Library/Application Support/iPhone Simulator/6.0/Applications/8F08C873-76C7-406F-AEAD-B499137787DD

五、HelloWorld.app 目录

                NSString *appPath =[ [NSBundle MainBundle] BundlePath];

             结果类似:

              ~/Library/Application Support/iPhone Simulator/6.0/Applications/8F08C873-76C7-406F-AEAD-B499137787DD/HelloWorld.app

六、获取Documents目录

            NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoey,NSUserDomainMask,YES);

            NSString *path = [paths objectAtIndex:0];

            结果类似:

                ~/Library/Application Support/iPhone Simulator/6.0/Applications/8F08C873-76C7-406F-AEAD-B499137787DD/Documents

七、获取Library 目录

            NSArray *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);

            NSString *path = [paths objectAtIndex:0];

           结果类似:

             ~/Library/Application Support/iPhone Simulator/6.0/Applications/8F08C873-76C7-406F-AEAD-B499137787DD/Library

八、获取Caches目录

            NSArray *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);           

           NSString *path = [paths objectAtIndex:0];

           结果类似:

九、获取Tmp目录

            

             NSString *tmpDir = NSTemporaryDirectory();

           结果类似:

              ~/Library/Application Support/iPhone Simulator/6.0/Applications/8F08C873-76C7-406F-AEAD-B499137787DD/Tmp

十、获取应用程序程序包中资源文件路径的方法:
例如获取程序包中一个图片资源(apple.png)路径的方法:
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@”apple” ofType:@”png”];
UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];

  //1)第一种情况,文件图标是黄色的,文件夹是假的,都会拷贝到HelloWorld.app 中
    //而且文件名称不能重名
    NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@".jpg"];
    NSLog(@"image is %@",imagePath);
    
    NSString *imagePath2 = [[NSBundle mainBundle ]pathForResource:@"2.jpg" ofType:nil];
    NSLog(@"image2 is %@",imagePath2);
    
    //Users/L-ios/Library/Developer/CoreSimulator/Devices/F5988D84-CB68-4DEC-805E-414D905304BE/data/Containers/Bundle/Application/528B83A0-F896-4759-8B57-D4EE2DCDBBE6/各种目录获取.app/image2/1.jpg
    //2)第二种情况,文件夹图标是绿色的,这个文件真实存在,内容拷贝到HelloWorld.app中,
    NSString *image2Path = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"jpg" inDirectory:@"image2"];
    NSLog(@"image2path is %@",image2Path);
    
    NSString *image2Path2 = [[NSBundle mainBundle]pathForResource:@"2.jpg" ofType:nil inDirectory:@"image2"];
    NSLog(@"image2Path2 is %@ ",image2Path2);

Sandbox沙盒

标签:

原文地址:http://www.cnblogs.com/C-TX/p/5248726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!