開發中常遇到需要快取的需求,快取的時候我們就需要有乙個路徑,下面的**是獲取沙盒中的路徑的方法:
//獲取沙盒主目錄路徑
nsstring * homedirectory = nshomedirectory();
nslog(@"home === %@",homedirectory);
//獲取documents目錄路徑
nsarray * documentpaths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);
nsstring * documentdirectory = [documentpaths objectatindex:0];
nslog(@"document === %@",documentdirectory);
//獲取caches目錄路徑
nsarray * cachespaths = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes);
nsstring * cachesdirectory = [cachespaths objectatindex:0];
nslog(@"caches === %@",cachesdirectory);
//獲取tmp目錄路徑
nsstring * tmpdirectory = nstemporarydirectory();
nslog(@"tmp === %@",tmpdirectory);
列印結果:
home === /users/zhanqin/library/developer/coresimulator/devices/50c4f22b-
903e-47ef-a3f2
-75cc-
4771
-8c58-
2b2a75ff2efc
document === /users/zhanqin/library/developer/coresimulator/devices/50c4f22b-
903e-47ef-a3f2
-75cc-
4771
-8c58-
2b2a75ff2efc/documents
caches === /users/zhanqin/library/developer/coresimulator/devices/50c4f22b-
903e-47ef-a3f2
-75cc-
4771
-8c58-
2b2a75ff2efc/library/caches
tmp === /users/zhanqin/library/developer/coresimulator/devices/50c4f22b-
903e-47ef-a3f2
-75cc-
4771
-8c58-
2b2a75ff2efc/tmp/
這幾個目錄的詳細區別於使用在這裡不做介紹,寫在這裡,用的時候比較方便。 獲取沙盒中路徑的方法
1,獲取家目錄路徑的函式 nsstring homedir nshomedirectory 2,獲取documents目錄路徑的方法 nsarray paths nssearchpathfordirectoriesindomains nsdocumentdirectory,nsuserdomainm...
ios 手動清除本地沙盒中的快取資料
把 寫入 沙盒 void photofile 此處的方法是將寫到documents檔案中 如果寫入成功會彈出乙個警告框,提示儲存成功 nsstring strpathold nsbundle mainbundle pathforresource pin oftype png nsdata data ...
ios開發 沙盒機制 獲取路徑方法
ios開發筆記 chapter 12 將檔案資料永久儲存 nsarray paths nssearchpathdirectoryindomain nssearchpathdirectory directory,nssearchpathdomainmask domainmask,bool expand...