天天看点

iOS沙盒简单介绍

看看苹果的沙盒目录:

iOS沙盒简单介绍
iOS沙盒简单介绍

再附一张苹果官方的图

iOS沙盒简单介绍

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

首先:

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

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

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

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

documents

library:又包括caches和preferences

temp

其中的

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

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

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

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

也就是documents的路径.

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

得到如下结果:

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

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

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

返回结果:

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

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

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

appname<code>.app</code>

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.

<code>documents/</code>

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.

<code>documents/inbox</code>

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.

<code>library/</code>

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 <code>application support</code> and <code>caches</code> subdirectories; however, you can create custom subdirectories.

use the <code>library</code> 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 <code>library</code> directory (with the exception of the <code>caches</code> subdirectory) are backed up by itunes.

<code>tmp/</code>

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.

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