天天看點

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.

英語好的大神可以看一下。不好的飄過,,,,

繼續閱讀