zoukankan      html  css  js  c++  java
  • iOS中的沙盒机制

    IOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容。所有的非代码文件都保存在这个地方,比如图片、声音、属性列表和文本文件等。

    1.每个应用程序都在自己的沙盒内

    2.不能随意跨越自己的沙盒去访问别的应用程序沙盒的内容

    3.应用程序向外请求或接收数据都需要经过权限认证

     

    查看模拟器的沙盒文件夹在Mac电脑上的存储位置,首先,这个文件夹是被隐藏的,所以要先将这些文件显示出来,打开命令行:

     

    显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true

     

    隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false

     

    然后重新启动Finder,点击屏幕左上角苹果标志——强制退出——选择Finder然后点击重新启动,这个时候在重新打开Finder就可以看到被隐藏的文件了。

     

    还有一种比较简单的办法就是直接点击Finder图标右键——前往文件夹——输入/Users/your username/Library/Application Support/iPhone Simulator/ ,然后确认就可以了。your username是你本机的用户名

    获取文件、library、temp 路径的代码如下:

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSString *homePath = NSHomeDirectory();
        NSLog(@"Home 目录:%@",homePath);
        
        NSArray *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
        NSString *documentsPath = [docPath objectAtIndex:0];
        NSLog(@"Documents 目录%@",documentsPath);
        
        
        NSArray *cacPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory  , NSUserDomainMask, YES);
        NSString *cachePath = [cacPath objectAtIndex:0];
        NSLog(@"%@",cachePath);
        
        NSArray *libsPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        NSString *libraryPath = [libsPath objectAtIndex:0];
        NSLog(@"%@",libraryPath);
        
        NSString *tempPath = NSTemporaryDirectory();
        NSLog(@"%@",tempPath);
        
        
        
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    数据库表数据传输到Oracle方案
    Pdnovel 在线阅读体验
    Metaweblog博客分发体验
    Liveqrcode活码系统设计
    Java Language Changes for Java SE 9
    利用“计算器”和公式做房贷计算
    阿里云SLB快速切换至https
    Charles 协助解决 metaweblog 排序问题
    Go语言网络通信---连续通信的UDP编程
    Go语言网络通信---一个简单的UDP编程
  • 原文地址:https://www.cnblogs.com/yuqingzhude/p/4836528.html
Copyright © 2011-2022 走看看