iOS App 升級(jí)時(shí)文件的保留情況

有這樣一個(gè)問(wèn)題淋叶,用戶用iOS設(shè)備下載了大量的數(shù)據(jù)咐刨,保存在設(shè)備本地码俩,如果用戶升級(jí)了應(yīng)用本身度帮,這些文件是否仍然存在。
找了一些官方解釋和Stackflow上的說(shuō)明


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 inside your app’s home directory. 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:
Put user data in the <Application_Home>/Documents/. User data is any data that cannot be recreated by your app, such as user documents and other user-generated content.

Handle support files—files your application downloads or generates and can recreate as needed—in one of two ways:
In iOS 5.0 and earlier, put support files in the <Application_Home>/Library/Caches directory to prevent them from being backed up

In iOS 5.0.1 and later, put support files in the <Application_Home>/Library/Application Support directory and apply thecom.apple.MobileBackup extended attribute to them. This attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.

Put data cache files in the <Application_Home>/Library/Caches directory. Examples of files you should put in this directory include (but are not limited to) database cache files and downloadable content, such as that used by magazine, newspaper, and map apps. Your app should be able to gracefully handle situations where cached data is deleted by the system to free up disk space.

Put temporary data in the <Application_Home>/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.

也就是說(shuō)稿存,一般從網(wǎng)上下載的那些內(nèi)容笨篷,包括雜志、報(bào)紙瓣履、視頻什么的率翅,都要放在 <Application_Home>/Library/Caches 目錄下面<Application_Home>/Library/

This directory is the top-level directory for files that are not user data files. You typically put files in one of several standard subdirectories but you can also create custom subdirectories for files you want backed up but not exposed to the user. You should not use this directory for user data files.
The contents of this directory (with the exception of the Caches subdirectory) are backed up by iTunes.
For additional information about the Library directory, see “The Library Directory Stores App-Specific Files.”

Library目錄下面的內(nèi)容,也會(huì)被被iTunes備份袖迎,但是Caches目錄除外冕臭,也就是說(shuō)這些網(wǎng)絡(luò)下載內(nèi)容文件放在這里是不會(huì)被備份的,

Caches

Use this directory to write any app-specific support files that your app can re-create easily. Your app is generally responsible for managing the contents of this directory and for adding and deleting files as needed.
In iOS 2.2 and later, the contents of this directory are not backed up by iTunes. In addition, iTunes removes files in this directory during a full restoration of the device.
On iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running. However, you should be aware that iTunes restore is not necessarily the only condition under which the Caches directory can be erased.

上面寫的的比較清楚燕锥,Library/Caches目錄下浴韭,一般情況下是不會(huì)被刪除的,我理解脯宿,也包括stackoverflow網(wǎng)友的證明念颈,應(yīng)用升級(jí)的時(shí)候也不會(huì)被刪除,實(shí)際上连霉,應(yīng)用升級(jí)的具體系統(tǒng)操作是這樣的:

Files Saved During Application Updates When a user downloads an application update, iTunes installs the update in a new application directory. It then moves the user’s data files from the old installation over to the new application directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:
Application_Home/Documents
Application_Home/Library

Although files in other user directories may also be moved over, you should not rely on them being present after an update.
系統(tǒng)先新建一個(gè)應(yīng)用目錄榴芳,然后安裝一個(gè)新版本應(yīng)用嗡靡,然后再把舊版本的應(yīng)用數(shù)據(jù)拷貝過(guò)來(lái),然后再刪除舊版本的應(yīng)用安裝目錄窟感。
最后注意一下讨彼,Library/Caches目錄下的數(shù)據(jù)雖然在一般情況下不會(huì)被刪除,但是在系統(tǒng)恢復(fù)和其他一些罕見(jiàn)的情況下(比如非常底的磁盤空間條件下有可能)會(huì)被清除柿祈,所以你的程序每次都要檢查一些哈误,這些文件都還在不在了,不在的話只能重新下了躏嚎。
Application_Home/Library/Caches Use this directory to write any application-specific support files that you want to persist between launches of the application or during application updates. Your application is generally responsible for adding and removing these files. It should also be able to re-create these files as needed because iTunes removes them during a full restoration of the device. In iOS 2.2 and later, the contents of this directory are not backed up by iTunes.

參考連接:http://stackoverflow.com/questions/7155964/will-application-home-library-caches-be-clear-on-app-update/7277797#7277797
File System Programming Guide
https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末蜜自,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子卢佣,更是在濱河造成了極大的恐慌重荠,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,639評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件虚茶,死亡現(xiàn)場(chǎng)離奇詭異戈鲁,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)嘹叫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,277評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門婆殿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人罩扇,你說(shuō)我怎么就攤上這事婆芦。” “怎么了暮蹂?”我有些...
    開(kāi)封第一講書人閱讀 157,221評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)癌压。 經(jīng)常有香客問(wèn)我仰泻,道長(zhǎng),這世上最難降的妖魔是什么滩届? 我笑而不...
    開(kāi)封第一講書人閱讀 56,474評(píng)論 1 283
  • 正文 為了忘掉前任集侯,我火速辦了婚禮,結(jié)果婚禮上帜消,老公的妹妹穿的比我還像新娘棠枉。我一直安慰自己,他們只是感情好泡挺,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,570評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布辈讶。 她就那樣靜靜地躺著,像睡著了一般娄猫。 火紅的嫁衣襯著肌膚如雪贱除。 梳的紋絲不亂的頭發(fā)上生闲,一...
    開(kāi)封第一講書人閱讀 49,816評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音月幌,去河邊找鬼碍讯。 笑死,一個(gè)胖子當(dāng)著我的面吹牛扯躺,可吹牛的內(nèi)容都是我干的捉兴。 我是一名探鬼主播,決...
    沈念sama閱讀 38,957評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼录语,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼倍啥!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起钦无,我...
    開(kāi)封第一講書人閱讀 37,718評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤逗栽,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后失暂,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體彼宠,經(jīng)...
    沈念sama閱讀 44,176評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,511評(píng)論 2 327
  • 正文 我和宋清朗相戀三年弟塞,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了凭峡。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,646評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡决记,死狀恐怖摧冀,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情系宫,我是刑警寧澤索昂,帶...
    沈念sama閱讀 34,322評(píng)論 4 330
  • 正文 年R本政府宣布,位于F島的核電站扩借,受9級(jí)特大地震影響椒惨,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜潮罪,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,934評(píng)論 3 313
  • 文/蒙蒙 一康谆、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧嫉到,春花似錦沃暗、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 30,755評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至细层,卻和暖如春忱叭,著一層夾襖步出監(jiān)牢的瞬間隔崎,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 31,987評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工韵丑, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留爵卒,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,358評(píng)論 2 360
  • 正文 我出身青樓撵彻,卻偏偏與公主長(zhǎng)得像钓株,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子陌僵,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,514評(píng)論 2 348

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