沙盒

作者: 冰J冰 | 来源:发表于2016-01-28 14:39 被阅读137次

IOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容。所有的非代码文件都保存在这个地方,比如图片、声音、属性列表和文本文件等。
1.每个应用程序都在自己的沙盒内
2.不能随意跨越自己的沙盒去访问别的应用程序沙盒的内容
3.应用程序向外请求或接收数据都需要经过权限认证


查看沙盒使用xcode 控件
需要alcatraz:xcode 插件管理工具

Paste_Image.png

一个完整的沙盒路径


Paste_Image.png
defaults write com.apple.finder AppleShowAllFiles -bool true

终端

显示Mac隐藏文件的命令:

defaults write com.apple.finder AppleShowAllFiles -bool true

隐藏Mac隐藏文件的命令:

defaults write com.apple.finder AppleShowAllFiles -bool false
//获取根目录  
    NSString *homePath = NSHomeDirectory();  
    NSLog(@"Home目录:%@",homePath);  
      
    //获取Documents文件夹目录,第一个参数是说明获取Doucments文件夹目录,第二个参数说明是在当前应用沙盒中获取,所有应用沙盒目录组成一个数组结构的数据存放  
    NSArray *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
    NSString *documentsPath = [docPath objectAtIndex:0];  
    NSLog(@"Documents目录:%@",documentsPath);  
      
    //获取Cache目录  
    NSArray *cacPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);  
    NSString *cachePath = [cacPath objectAtIndex:0];  
    NSLog(@"Cache目录:%@",cachePath);  
      
    //Library目录  
    NSArray *libsPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);  
    NSString *libPath = [libsPath objectAtIndex:0];  
    NSLog(@"Library目录:%@",libPath);  
      
    //temp目录  
    NSString *tempPath = NSTemporaryDirectory();  
    NSLog(@"temp目录:%@",tempPath);  

下面开始向目录里面创建文件,然后向文件里面写入内容

NSArray *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
    NSString *documentsPath = [docPath objectAtIndex:0];  
    //写入文件  
    if (!documentsPath) {  
        NSLog(@"目录未找到");  
    }else {  
        NSString *filePaht = [documentsPath stringByAppendingPathComponent:@"test.txt"];  
        NSArray *array = [NSArray arrayWithObjects:@"Title",@"Contents", nil];  
        [array writeToFile:filePaht atomically:YES];  
    } 


NSArray *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
    NSString *documentsPath = [docPath objectAtIndex:0];  
    NSString *readPath = [documentsPath stringByAppendingPathComponent:@"test.txt"];  
    NSArray *fileContent = [[NSArrayalloc] initWithContentsOfFile:readPath];  
    NSLog(@"文件内容:%@",fileContent);

相关文章

  • IOS沙盒 - OC

    沙盒: 沙盒包含: 沙盒路径获取的方法:

  • Objective-C沙盒结构

    导读: 一、什么是沙盒机制二、沙盒的特点三、沙盒的结构组成四、获取沙盒目录路径 一、什么是沙盒机制 iOS中的沙盒...

  • iOS 数据持久化知识汇总(1)—————存储路径

    一、沙盒和沙盒存储路径 1、沙盒是什么 iOS 每个iOS应用都有自己的应用沙盒,应用沙盒就是文件系统目录 。所...

  • OC - 沙盒

    导读: 一、什么是沙盒机制 二、沙盒的特点 三、沙盒的结构组成 四、获取沙盒目录路径 一、什么是沙盒机制 iOS中...

  • 沙盒

    1、沙盒 程序只能访问自己的沙盒 NSHomeDirectory() 访问沙盒路径 沙盒下有三个目录:Docume...

  • iOS 系统相关复习

    沙盒 iOS沙盒详细介绍iOS沙盒篇 沙盒机制介绍 iOS中的沙盒机制是一种安全体系。为了保证系统安全,iOS每个...

  • iOS开发之沙盒机制

    沙盒 iOS系统,每个应用都有自己的沙盒,每个沙盒都是相互独立的,不能互相访问。 获取沙盒路径的代码: NSHom...

  • 数据持久化存储

    沙盒 iOS程序默认情况下只能访问自己的目录,这个目录被称作沙盒 沙盒结构 沙盒结构主要为 DocumentLib...

  • iOS的永久话储存

    沙盒:IOS应用中每个应用均有自己沙盒,用来储存APP自己的数据,每个应用的沙盒均是应用特有的不能交叉访问。 沙盒...

  • iOS沙盒解析及操作

    介绍 概念:每个应用拥有自己的应用沙盒,所谓的应用沙盒就是文件系统目录。 沙盒文件目录 沙盒操作 获取应用根目录 ...

网友评论

      本文标题:沙盒

      本文链接:https://www.haomeiwen.com/subject/suhjkttx.html