iOS數(shù)據(jù)存儲

一? An iOS app operating within its own sandbox directory

在自己的沙盒目錄下運行的iOS應(yīng)用程序

An app is generally prohibited from accessing or creating files outside its container directories. One exception to this rule is when an app uses public system interfaces to access things such as the user’s contacts or music. In those cases, the system frameworks use helper apps to handle any file-related operations needed to read from or modify the appropriate data stores.

應(yīng)用程序通常不允許在它的容器目錄之外訪問或創(chuàng)建文件。一個例外是當(dāng)應(yīng)用程序使用公共系統(tǒng)接口去訪問例如用戶的聯(lián)系人或音樂。在這些場景,系統(tǒng)框架使用開發(fā)者幫助文檔去處理需要從適當(dāng)?shù)臄?shù)據(jù)存儲讀取或修改的任何文件相關(guān)的操作绪穆。

二? Where You Should Put Your App’s Files

To prevent the syncing and backup processes on iOS devices from taking a long time, be selective about where you place files. Apps that store large files can slow down the process of backing up to iTunes or iCloud. These apps can also consume a large amount of a user's available storage, which may encourage the user to delete the app or disable backup of that app's data to iCloud. With this in mind, you should store app data according to the following guidelines:

為了防止在iOS設(shè)備同步和備份使用很長的時間钠怯,你的文件存儲位置是可以被選擇的。存儲大文件的應(yīng)用程序會減慢備份到iTunes或iCloud的過程节值,這些應(yīng)用也會消耗大量用戶可用空間锯梁。這些都會促使用戶刪除應(yīng)用或者不再備份應(yīng)用的數(shù)據(jù)到iCloud适贸。基于此涝桅,你應(yīng)該按照如下指南進行存儲應(yīng)用數(shù)據(jù)。

Put user data in Documents/. User data generally includes any files you might want to expose to the user—anything you might want the user to create, import, delete or edit. For a drawing app, user data includes any graphic files the user might create. For a text editor, it includes the text files. Video and audio apps may even include files that the user has downloaded to watch or listen to later.

將用戶數(shù)據(jù)存放在Documents/. 路徑烙样。用戶數(shù)據(jù)一般包括你可能想暴露給用戶的任何文件冯遂,你可能想讓用戶創(chuàng)建、引入谒获、刪除或編輯的任何數(shù)據(jù)蛤肌。對于一個繪制應(yīng)用程序,用戶數(shù)據(jù)包含用戶可能創(chuàng)建的任何圖表文件批狱。對于一個文本編輯器裸准,它包含一些文本文件。視頻和音頻類應(yīng)用可能甚至包含用戶已經(jīng)下載后要觀看或收聽的文件赔硫。

Put app-created support files in the Library/Application support/ directory. In general, this directory includes files that the app uses to run but that should remain hidden from the user. This directory can also include data files, configuration files, templates and modified versions of resources loaded from the app bundle.

將應(yīng)用創(chuàng)建的支持文件放在路徑Library/Application support/ directory炒俱,一般而言,這個目錄包含應(yīng)用運行需要的但是對用戶而言應(yīng)該要隱藏的文件爪膊。該目錄還可以包含從app bundle中加載的數(shù)據(jù)文件权悟、配置文件、模板和修改版本的資源

Remember that files in Documents/ and Application Support/ are backed up by default. You can exclude files from the backup by calling -[NSURL setResourceValue:forKey:error:] using the NSURLIsExcludedFromBackupKey key. Any file that can be re-created or downloaded must be excluded from the backup. This is particularly important for large media files. If your application downloads video or audio files, make sure they are not included in the backup.

記得Documents/ and Application Support/目錄下的文件默認(rèn)會備份推盛。通過使用NSURLIsExcludedFromBackupKey鍵調(diào)用-[NSURL setResourceValue:forKey:error:]可以從備份中排除文件峦阁。任何可以重新創(chuàng)建或下載的文件都必須排除在備份之外。這對于大型媒體文件來說尤其重要耘成。如果你的應(yīng)用下載視頻或音頻文件榔昔,確認(rèn)他們不是包含在備份中驹闰。

Put temporary data in the tmp/ directory. Temporary data comprises any data that you do not need to persist for an extended period of time. Remember to delete those files when you are done with them so that they do not continue to consume space on the user’s device. The system will periodically purge these files when your app is not running; therefore, you cannot rely on these files persisting after your app terminates.

將臨時文件存儲在tmp/目錄。臨時數(shù)據(jù)包含你不需要長期使用的任何數(shù)據(jù)撒会。記得去刪除這些文件當(dāng)你已經(jīng)使用完了嘹朗,因此他們不會繼續(xù)占用用戶設(shè)備的空間。當(dāng)應(yīng)用不再運行時系統(tǒng)將會定時清除這些文件茧彤;因此當(dāng)應(yīng)用終止時你不能依賴這些文件持久化

Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.

將數(shù)據(jù)緩存文件存儲在Library/Caches/ 目錄骡显。緩存數(shù)據(jù)可以應(yīng)用于任何需要比臨時文件持久化的數(shù)據(jù),但是沒有支持文件更久曾掂。一般而言惫谤,應(yīng)用不會要求緩存數(shù)據(jù)也能正確操作,但它可以使用緩存數(shù)據(jù)來提升性能珠洗。緩存數(shù)據(jù)的例子包含(但不限于)數(shù)據(jù)庫緩存文件和臨時的溜歪、可下載的內(nèi)容。系統(tǒng)會刪除Caches/目錄清空磁盤空間许蓖,因此當(dāng)需要這些文件的時候你的應(yīng)用必須可以重新創(chuàng)建或下載蝴猪。

三 總結(jié)

1、存儲內(nèi)容類型

/Documents一般會存儲用戶生成的內(nèi)容,此目錄應(yīng)該只包含您可能希望向用戶公開的文件

/Library/ 一般不會存儲用戶數(shù)據(jù)文件膊爪,此目錄包含不希望向用戶公開的任何文件

/tmp/? 一般會存儲在應(yīng)用程序啟動期間不需要持久保存的臨時文件自阱,此目錄會在應(yīng)用不再運行時被清空

2、文件備份情況

/Documents這個目錄的內(nèi)容由iTunes和iCloud備份

/Library/? ? ? ??這個目錄的內(nèi)容由iTunes和iCloud備份

/tmp/? ? ? ? ? ? 這個目錄的內(nèi)容沒有iTunes或iCloud備份

四 目錄說明

Table 1-1 lists some of the more important subdirectories inside the sandbox directory and describes their intended usage. This table also describes any additional access restrictions for each subdirectory and points out whether the directory’s contents are backed up by iTunes and iCloud.

表格1-1列出了一些在沙盒目錄更重要的子目錄并描述了它們的預(yù)期用途米酬。這個表格也描述了對于每個子目錄的任何額外訪問限制沛豌,同時指出了目錄內(nèi)容是否從iTunes和iCloud中備份的。

Directory / Description

AppName.app

This is the app’s bundle. This directory contains the app and all of its resources.You cannot write to this directory. To prevent tampering, the bundle directory is signed at installation time. Writing to this directory changes the signature and prevents your app from launching. You can, however, gain read-only access to any resources stored in the apps bundle. For more information, see the Resource Programming Guide.The contents of this directory are not backed up by iTunes or iCloud. However, iTunes does perform an initial sync of any apps purchased from the App Store.

Documents/

Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, this directory should only contain files that you may wish to expose to the user.The contents of this directory are backed up by iTunes and iCloud.

Documents/Inbox

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.The contents of this directory are backed up by iTunes and iCloud.

Library/

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 Application Support and Caches subdirectories; however, you can create custom subdirectories.Use the Library 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 Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files.

tmp/

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 or iCloud.


五? 文檔相關(guān)

文檔參考? https://developer.apple.com

如對讀書赃额、測試感興趣的小伙伴可關(guān)注如下WeChat:琦哥私房菜加派,小編會分享讀書筆記和測試技術(shù)文章,希望同大家一起進步跳芳。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末芍锦,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子飞盆,更是在濱河造成了極大的恐慌娄琉,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,639評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件桨啃,死亡現(xiàn)場離奇詭異车胡,居然都是意外死亡,警方通過查閱死者的電腦和手機照瘾,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,277評論 3 385
  • 文/潘曉璐 我一進店門匈棘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人析命,你說我怎么就攤上這事主卫√幽” “怎么了?”我有些...
    開封第一講書人閱讀 157,221評論 0 348
  • 文/不壞的土叔 我叫張陵簇搅,是天一觀的道長完域。 經(jīng)常有香客問我,道長瘩将,這世上最難降的妖魔是什么吟税? 我笑而不...
    開封第一講書人閱讀 56,474評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮姿现,結(jié)果婚禮上肠仪,老公的妹妹穿的比我還像新娘。我一直安慰自己备典,他們只是感情好异旧,可當(dāng)我...
    茶點故事閱讀 65,570評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著提佣,像睡著了一般吮蛹。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上拌屏,一...
    開封第一講書人閱讀 49,816評論 1 290
  • 那天潮针,我揣著相機與錄音,去河邊找鬼倚喂。 笑死然低,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的务唐。 我是一名探鬼主播,決...
    沈念sama閱讀 38,957評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼带兜,長吁一口氣:“原來是場噩夢啊……” “哼枫笛!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起刚照,我...
    開封第一講書人閱讀 37,718評論 0 266
  • 序言:老撾萬榮一對情侶失蹤刑巧,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后无畔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體啊楚,經(jīng)...
    沈念sama閱讀 44,176評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,511評論 2 327
  • 正文 我和宋清朗相戀三年浑彰,在試婚紗的時候發(fā)現(xiàn)自己被綠了恭理。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,646評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡郭变,死狀恐怖颜价,靈堂內(nèi)的尸體忽然破棺而出涯保,到底是詐尸還是另有隱情,我是刑警寧澤周伦,帶...
    沈念sama閱讀 34,322評論 4 330
  • 正文 年R本政府宣布夕春,位于F島的核電站,受9級特大地震影響专挪,放射性物質(zhì)發(fā)生泄漏及志。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,934評論 3 313
  • 文/蒙蒙 一寨腔、第九天 我趴在偏房一處隱蔽的房頂上張望速侈。 院中可真熱鬧,春花似錦脆侮、人聲如沸锌畸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,755評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽潭枣。三九已至,卻和暖如春幻捏,著一層夾襖步出監(jiān)牢的瞬間盆犁,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,987評論 1 266
  • 我被黑心中介騙來泰國打工篡九, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留谐岁,地道東北人。 一個月前我還...
    沈念sama閱讀 46,358評論 2 360
  • 正文 我出身青樓榛臼,卻偏偏與公主長得像伊佃,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子沛善,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,514評論 2 348

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