下面介紹一下沙箱的
目錄結構:
預設情況下,每個沙盒含有3個資料夾:documents, library 和 tmp和乙個應用程式檔案(也是乙個檔案)。因為應用的沙盒機制,應用只能在幾個目錄下讀寫檔案
documents:蘋果建議將程式中建立的或在程式中瀏覽到的檔案資料儲存在該目錄下,itunes備份和恢復的時候會包括此目錄
library:儲存程式的預設設定或其它狀態資訊;
library/caches:存放快取檔案,itunes不會備份此目錄,此目錄下檔案不會在應用退出刪除
tmp:提供乙個即時建立臨時檔案的地方。
itunes在與iphone同步時,備份所有的documents和library檔案。
iphone在重啟時,會丟棄所有的tmp檔案。
一整套讀寫
//1、獲取程式的home目錄nsstring *homedirectory = nshomedirectory();
nslog(@"path:%@", homedirectory);
//2、獲取document目錄
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);
nsstring *path = [paths objectatindex:0];
nslog(@"path:%@", path);
//3、獲取cache目錄
nsarray *paths = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes);
nsstring *path = [paths objectatindex:0];
nslog(@"path:%@", path);
//4、獲取library目錄
nsarray *paths = nssearchpathfordirectoriesindomains(nslibrarydirectory, nsuserdomainmask, yes);
nsstring *path = [paths objectatindex:0];
nslog(@"path:%@", path);
//5、獲取tmp目錄
nsstring *tmpdir = nstemporarydirectory();
nslog(@"path:%@", tmpdir);
在某目錄下建立乙個檔案
4.1 、在document中建立乙個檔案目錄
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);
nsstring *documentsdirectory = [paths objectatindex:0];
nslog(@"documentsdirectory%@",documentsdirectory);
nsfilemanager *filemanager = [nsfilemanager defaultmanager];
// 建立目錄
[filemanager createdirectoryatpath:testdirectory withintermediatedirectories:yes attributes:nil error:nil];
iOS沙盒 一 沙盒機制
1 ios沙盒機制 ios應用程式只能在為該改程式建立的檔案系統中讀取檔案,不可以去其它地方訪問,此區域被成為沙盒,所以所有的非 檔案都要儲存在此,例如影象,圖示,聲音,映像,屬性列表,文字檔案等。1.1 每個應用程式都有自己的儲存空間 1.2 應用程式不能翻過自己的圍牆去訪問別的儲存空間的內容 1...
IOS 沙盒機制
ios沙盒機制 sandbox ios中的沙盒機制是一種安全體系,它規定了應用程式只能在為該應用程式建立的資料夾裡讀取檔案,不可以訪問其他地方的內容,所有的非 檔案都儲存在這個地方,比如 聲音 屬性列表和文字檔案等。1.每個應用程式都在自己的沙盒內 2.應用程式間不能共享資料,不能隨意去訪問別的應用...
iOS沙盒機制
ios沙盒機制 ios應用程式只能在為該改程式建立的檔案系統中讀取檔案,不可以去其它地方訪問,此區域被成為沙盒,所以所有的非 檔案都要儲存在此,例如影象,圖示,聲音,映像,屬性列表,文字檔案等。1.1 每個應用程式都有自己的儲存空間 1.2 應用程式不能翻過自己的圍牆去訪問別的儲存空間的內容 1.3...