問題描述
我已經(jīng)閱讀了 Apple 的數(shù)據(jù)存儲指南,并且對于我應(yīng)該將我在我的應(yīng)用程序中創(chuàng)建的 sqlite 數(shù)據(jù)庫文件保存在哪里感到非常困惑.即使應(yīng)用程序處于離線模式,我也想從 sqlite 文件中讀取.我讀到,創(chuàng)建的此類文件應(yīng)保存在庫/緩存中,并設(shè)置不備份"標(biāo)志.請建議我做同樣事情的正確方法.
答案取決于你的數(shù)據(jù)庫文件是如何創(chuàng)建的:
根據(jù)數(shù)據(jù)存儲指南頁面:
<塊引用>只有用戶生成的或您的應(yīng)用程序無法重新創(chuàng)建的文檔和其他數(shù)據(jù)才能存儲在/Documents 目錄,將自動由 iCloud 備份.
可以再次下載或重新生成的數(shù)據(jù)應(yīng)存儲在/Library/Caches 目錄中.文件示例你應(yīng)該在 Caches 目錄下包含數(shù)據(jù)庫緩存文件和可下載的內(nèi)容,例如雜志、報紙使用的內(nèi)容,和地圖應(yīng)用程序.
這對我來說似乎比較清楚:如果您的應(yīng)用程序以編程方式創(chuàng)建某些內(nèi)容或生成您想要保存的數(shù)據(jù),請將其放在緩存"文件夾中.如果這是客戶自己生成的獨特內(nèi)容(通過鍵盤輸入或他們手動干預(yù)并執(zhí)行的操作),請將其放入文檔"中.
不備份"意味著文件永遠(yuǎn)不會發(fā)送到 iCloud,如果丟失,則必須從頭開始重新創(chuàng)建(或重新安裝).
I have read the Data Storage guidelines of Apple and am really confused as to where i should keep the sqlite database files i am creating in my app. I want to read from the sqlite files even when the app is in Offfline mode. I read that such files created should be kept in the Library/caches with the "do not backup" flag set. Please suggest me the right approach for doing the same.
The answer depends on how your database files are created:
According to the Data Storage Guidelines page:
Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.
Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.
This seems relatively clear to me: if your app programatically creates something or generates data that you want saved, put it in the "Caches" folder. If it's something unique that the customer themselves generate (via typing into a keyboard or something they manually intervened and did), put it in "Documents".
"Do Not Backup" means that the files never get sent up to iCloud and if they get lost, they have to be re-created from scratch (or re-install).
這篇關(guān)于我應(yīng)該將 sqlite 數(shù)據(jù)庫文件寫入 Documents 目錄還是 Library/Caches?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!