先简单介绍一下什么是沙盒:你可以简单理解成为一个目录,这个目录的改动不会对操作系统造成任何损失。(这里也有一点点介绍

看看苹果的沙盒目录:

再附一张苹果官方的图

一个iOS app操作都是在自己的沙盒中进行的。

首先:

Deveices,里面是各种的模拟器设备。

然后随便找一个模拟器设备。里面的data是里面的数据。然后Container里面Data中有一个Application就是该设备的安装软件。

我们可以看到里面有好多个(就算我们Reset Content and Settings,也会有。因为里面有设备自带的软件,例如通讯录,地图等。)。

随便打开一个就可以看到里面某个程序包括三个目录:

Documents

Library:又包括Caches和Preferences

temp

其中的

Documents只有用户生成的文件、其他的数据以及程序程序不能创建的文件,这里的数据通过iCloud自动备份。我们录制的音频和拍照的图片都可以放到这里。

Library:可以重新下载或者重新生成的数据应该保存在Library的caches目录中。这里用于盛放缓存。

tmp:是临时使用的数据。iCloud不会自动备份这些文件,这些数据使用完后要随时删除,避免占用用户设备空间。

- (NSString *)documentDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:];
}

通过上面这个方法可以得到:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/--481D-B8CB-B25EB4B787E2/Documents

也就是Documents的路径.

还可以得到通过下面的方法:

 NSString *s = NSHomeDirectory();

得到如下结果:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/08A6D627--48B4-8AF8-A1ED361DC9D6

故名思议,我们通过NSHomeDirectory得到了该安装软件的目录。(里面就包括Documents/Library/temp)

苹果官方介绍的是返回用户的或者应用程序的家目录,依赖于平台。

再来看一下如何取得Caches目录路径的方法:

  NSString *s = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:];

返回结果:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/DB647E93-5F05-4B7B-A8E9-F6F01DD2586B/Library/Caches

最后看一下如何获取tmp目录:

  NSString *s = NSTemporaryDirectory();

返回结果:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/C7CA833E-8D20-480B-AB91-234A8F17336D/tmp/

--------------------------------------------------------------------大概就这么多吧--------------------------------------------------------------------

NO ,NO ,NO看看苹果官方的说明吧:

AppName.app

This is the app’s bundle. This directory contains the app and all of its resources.

You cannot write to this directory. To prevent tampering, the bundle directory is signed at installation time. Writing to this directory changes the signature and prevents your app from launching. You can, however, gain read-only access to any resources stored in the apps bundle. For more information, see theResource Programming Guide

The contents of this directory are not backed up by iTunes. However, iTunes does perform an initial sync of any apps purchased from the App Store.

Documents/

Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user.

The contents of this directory are backed up by iTunes.

Documents/Inbox

Use this directory to access files that your app was asked to open by outside entities. Specifically, the Mail program places email attachments associated with your app in this directory. Document interaction controllers may also place files in it.

Your app can read and delete files in this directory but cannot create new files or write to existing files. If the user tries to edit a file in this directory, your app must silently move it out of the directory before making any changes.

The contents of this directory are backed up by iTunes.

Library/

This is the top-level directory for any files that are not user data files. You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories.

Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.

The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes.

For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files.

tmp/

Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.

The contents of this directory are not backed up by iTunes.

英语好的大神可以看一下。不好的飘过,,,,

更多请见:https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

(2017年6月16日上午10:15更新)

近日有位开发者咨询了一个问题:将NSUserDefaults的plist删除之后再次打开app不会自动生成plist的问题。经过测试,苹果的NSUserDefaults存储数据是在Library--->Perference里面存储的,并且名字为:com.xxxx.xxxx.plist.该文件可以(开发过程中)直接被删除(通过iExplorer)。但是删除之后再次打开app是不会自动生成的,除非你重启了手机(并打开app)或者重新安装了app。这个应该是苹果的机制。而且重新生成的plist是不会包含你原来在里面存储的数据。

从AppStore上下载的程序我用工具无法查看到它的沙盒,所以也无从下手删除了。

iOS沙盒简单介绍的更多相关文章

  1. iOS 阶段学习第25天笔记(iOS沙盒机制介绍)

    iOS学习(OC语言)知识点整理 一.iOS沙盒机制介绍 1)概念: 每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用放入文件 系统隔离,ios系统不允许访问 其他应用的应用沙盒 ...

  2. iOS沙盒机制介绍,Block 的介绍

    一.iOS沙盒机制介绍 (转载) 1)概念:每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用放入文件 系统隔离,ios系统不允许访问 其他应用的应用沙盒,但在ios8中已经开放访 ...

  3. IOS 学习之 iOS沙盒(sandbox) 介绍 沙盒机制 文件操作(一)

    1.iOS沙盒机制 iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等. ...

  4. iOS沙盒文件目录介绍

    1.APP沙盒目录结构简介 首先奉上苹果官方文档: https://developer.apple.com/library/archive/documentation/FileManagement/C ...

  5. iOS沙盒机制介绍

    一.沙盒机制 沙盒的概念:沙盒是每一个iOS应用程序都会自动创建的一个文件系统目录(文件夹),而且沙盒还具有独立.封闭.安全的特点. 沙盒机制 iOS中的沙盒不仅仅是一个文件目录,TA其实更是一种安全 ...

  6. iOS 沙盒目录结构介绍

    iOS系统中,每个应用都有自己的沙盒,且应用只能访问其对应的沙盒目录下面的文件.当然,在用户授权的情况下,应用也可以访问其他目录下面的文件.比如,用户授权情况下,应用可以访问相册.通讯录.在开发中,经 ...

  7. iOS 沙盒(sandbox)机制和文件操作

    本文参看了 http://www.uml.org.cn/mobiledev/201209211.asp#1 这篇文章中的介绍,尊重原著. 1.IOS沙盒机制 IOS应用程序只能在本应用程序中创建的文件 ...

  8. IOS学习之IOS沙盒(sandbox)机制和文件操作

    IOS学习之IOS沙盒(sandbox)机制和文件操作(一) 1.IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都 ...

  9. IOS沙盒(sandbox)机制和文件操作

    IOS学习之IOS沙盒(sandbox)机制和文件操作   作者:totogo2010 ,发布于2012-9-21,来源:CSDN   目录: IOS学习之IOS沙盒(sandbox)机制和文件操作( ...

随机推荐

  1. ActivityGroup里面装的子Activity不执行OnActivityResult()的解决办法

    转自http://blog.csdn.net/snakewarhead/article/details/7976831 tab activity 中调用startActivityForResult 以 ...

  2. sourceinsight技巧

    Source Insight实质上是一个支持多种开发语言(java,c ,c++等等)的编辑器,只不过由于其查找.定位.彩色显示等功能的强大,常被我们当成源代码阅读工具使用. 所以,为了有效的阅读源程 ...

  3. 【转载】关于 Ubuntu 的小知识分享

    转载自:http://os.51cto.com/art/201307/402197.htm 一.默认开机直接进入到Ubuntu命令行界面 安装Ubuntu后,开机会默认进入到图形界面,如果不喜欢图形界 ...

  4. java中this关键字

    1.     当成员变量和局部变量重名时,在方法中使用this时,表示的是该方法所在类中的成员变量.(this是当前对象自己) 如:public class Hello { String s = &q ...

  5. ecshop中那些有意思的代码

    1:返回数量为0的array,而不是null /** * 获得推荐商品 * * @access public * @param string $type 推荐类型,可以是 best, new, hot ...

  6. python使用SMTP发送邮件

    SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.SMTP协议属于TCP/IP协议簇,它 ...

  7. IOS高级编程之二:IOS的数据存储与IO

    一.应用程序沙盒 IOS应用程序职能在系统为该应用所分配的文件区域下读写文件,这个文件区域就是应用程序沙盒.所有的非代码文件如:图片.声音.映象等等都存放在此. 在mac中command+shift+ ...

  8. mysql DDL时出现的锁等待状态

    如下表格所示: session1: session2: 10:30:27 root@localhost:[testdb] mysql.sock>select * from t2;+------+ ...

  9. Res_Orders_01之需求分析

    Res_Orders_01之需求分析 一.背景及好处 为了提高餐厅的运营效率,增强餐厅各部门间的配合,减少顾客到店后的点餐.等餐及结算过程消耗的时间,降低服务员点餐失误率,进一步提高餐厅管理人员对菜品 ...

  10. UnityShader快速上手指南(二)

    简介 前一篇介绍了如果编写最基本的shader,接下来本文将会简单的深入一下,我们先来看下效果吧 呃,gif效果不好,实际效果是很平滑的动态过渡 实现思路 1.首先我们要实现一个彩色方块 2.让色彩动 ...