沙盒之iOS筆記摘錄

目錄

床前明月光刁俭,疑是地上霜隅津。 舉頭望明月,低頭思故鄉(xiāng)绣溜。

前言

1. 沙盒

    當iOS系統(tǒng)安裝應用時库糠,會為該應用分配一塊獨立的空間(用來存放該應用的系統(tǒng)文件和緩存),該應用只能訪問該空間中的資源涮毫,這種機制稱之為沙盒機制瞬欧。

 有4個文件夾:
    1、應用名.app
    應用程序包:程序本身罢防,包含資源艘虎。是經(jīng)過加簽的,運行時不能修改咒吐。
    2野建、Documents
    存儲用戶下載或保存的數(shù)據(jù)。會被iTunes備份恬叹。
    3候生、Library      
    Caches文件夾:存儲SDWebImg...等緩存。不會被iTunes備份绽昼。
    Preferences文件夾:會被iTunes備份唯鸭。存儲系統(tǒng)偏好設置NSUserdefaults。
    4硅确、temp         
    存儲臨時文件目溉。不會被iTunes備份,應用銷毀后即清除菱农。
NSHomeDirectory() 沙盒根目錄
    // 存儲路徑
    NSString *path=[NSString stringWithFormat:@"%@/Documents/1.src",NSHomeDirectory()];

    // 獲取Documents目錄路徑
    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    // 獲取Library的目錄路徑
    NSString *libDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES) lastObject];
    // 獲取cache目錄路徑
    NSString *cachesDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) firstObject];
    // 獲取tmp目錄路徑
    NSString *tmpDir =NSTemporaryDirectory();
/*

第一個參數(shù):想要查找的目錄
ypedef NS_ENUM(NSUInteger, NSSearchPathDirectory) {
    NSApplicationDirectory = 1,             // supported applications (Applications)
    NSDemoApplicationDirectory,             // unsupported applications, demonstration versions (Demos)
    NSDeveloperApplicationDirectory,        // developer applications (Developer/Applications). DEPRECATED - there is no one single Developer directory.
    NSAdminApplicationDirectory,            // system and network administration applications (Administration)
    NSLibraryDirectory,                     // various documentation, support, and configuration files, resources (Library)
    NSDeveloperDirectory,                   // developer resources (Developer) DEPRECATED - there is no one single Developer directory.
    NSUserDirectory,                        // user home directories (Users)
    NSDocumentationDirectory,               // documentation (Documentation)
    NSDocumentDirectory,                    // documents (Documents)
    NSCoreServiceDirectory,                 // location of CoreServices directory (System/Library/CoreServices)
    NSAutosavedInformationDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 11,   // location of autosaved documents (Documents/Autosaved)
    NSDesktopDirectory = 12,                // location of user's desktop
    NSCachesDirectory = 13,                 // location of discardable cache files (Library/Caches)
    NSApplicationSupportDirectory = 14,     // location of application support files (plug-ins, etc) (Library/Application Support)
    NSDownloadsDirectory API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 15,              // location of the user's "Downloads" directory
    NSInputMethodsDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 16,           // input methods (Library/Input Methods)
    NSMoviesDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 17,                 // location of user's Movies directory (~/Movies)
    NSMusicDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 18,                  // location of user's Music directory (~/Music)
    NSPicturesDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 19,               // location of user's Pictures directory (~/Pictures)
    NSPrinterDescriptionDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 20,     // location of system's PPDs directory (Library/Printers/PPDs)
    NSSharedPublicDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 21,           // location of user's Public sharing directory (~/Public)
    NSPreferencePanesDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 22,        // location of the PreferencePanes directory for use with System Preferences (Library/PreferencePanes)
    NSApplicationScriptsDirectory NS_ENUM_AVAILABLE(10_8, NA) = 23,      // location of the user scripts folder for the calling application (~/Library/Application Scripts/code-signing-id)
    NSItemReplacementDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 99,      // For use with NSFileManager's URLForDirectory:inDomain:appropriateForURL:create:error:
    NSAllApplicationsDirectory = 100,       // all directories where applications can occur
    NSAllLibrariesDirectory = 101,          // all directories where resources can occur
    NSTrashDirectory API_AVAILABLE(macos(10.8), ios(11.0)) API_UNAVAILABLE(watchos, tvos) = 102             // location of Trash directory
};

第二個參數(shù):從哪個路徑區(qū)域查找
typedef NS_OPTIONS(NSUInteger, NSSearchPathDomainMask) {
   NSUserDomainMask =1,      // 用戶的主目錄
   NSLocalDomainMask =2,     // 當前機器的本地目錄
   NSNetworkDomainMask =4,    //在網(wǎng)絡中公開可用的位置
   NSSystemDomainMask =8,    // 被蘋果系統(tǒng)提供的缭付,不可更改的位置 (/System)
   NSAllDomainsMask = 0x0ffff  // 上述所有及未來的位置
};

第三個參數(shù):true時顯示具體路徑,false時使用~代替主目錄路徑循未。
*/

  // [NSBundle mainBundle] 返回的路徑是  .../項目名.app/
  NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"apple"ofType:@"png"];
  UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];

2. 下載手機應用的沙盒目錄

當項目遇到保存錄音內(nèi)容等需求時陷猫,會需要查看應用沙盒目錄。

步驟

1. XCode的Window下點擊Devices and Simulators
2. 單擊installapp中的指定應用,點擊設置按鈕绣檬,點擊DownloadContainer
3. 找到下載的.xcappdata文件舅巷,右鍵查看包內(nèi)容
XCode的Window下點擊Devices and Simulators
單擊installapp中的指定應用,點擊設置按鈕河咽,點擊DownloadContainer
找到下載的xcap文件钠右,右鍵查看包內(nèi)容
Documents
Library
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市忘蟹,隨后出現(xiàn)的幾起案子飒房,更是在濱河造成了極大的恐慌,老刑警劉巖媚值,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件狠毯,死亡現(xiàn)場離奇詭異,居然都是意外死亡褥芒,警方通過查閱死者的電腦和手機嚼松,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來锰扶,“玉大人献酗,你說我怎么就攤上這事】琅#” “怎么了罕偎?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長京闰。 經(jīng)常有香客問我颜及,道長,這世上最難降的妖魔是什么蹂楣? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任俏站,我火速辦了婚禮,結果婚禮上痊土,老公的妹妹穿的比我還像新娘肄扎。我一直安慰自己,他們只是感情好施戴,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布反浓。 她就那樣靜靜地躺著,像睡著了一般赞哗。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上辆雾,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天肪笋,我揣著相機與錄音,去河邊找鬼。 笑死藤乙,一個胖子當著我的面吹牛猜揪,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播坛梁,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼而姐,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了划咐?” 一聲冷哼從身側響起拴念,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎褐缠,沒想到半個月后政鼠,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡队魏,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年公般,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片胡桨。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡官帘,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出昧谊,到底是詐尸還是另有隱情遏佣,我是刑警寧澤,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布揽浙,位于F島的核電站状婶,受9級特大地震影響,放射性物質發(fā)生泄漏馅巷。R本人自食惡果不足惜膛虫,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望钓猬。 院中可真熱鬧稍刀,春花似錦、人聲如沸敞曹。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽澳迫。三九已至局齿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間橄登,已是汗流浹背抓歼。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工讥此, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人谣妻。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓萄喳,卻偏偏與公主長得像,于是被迫代替她去往敵國和親蹋半。 傳聞我的和親對象是個殘疾皇子他巨,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容