我已经阅读了 Apple 的数据存储指南,并且对于我应该将我在我的应用程序中创建的 sqlite 数据库文件保存在哪里感到非常困惑.即使应用程序处于离线模式,我也想从 sqlite 文件中读取.我读到,创建的此类文件应保存在库/缓存中,并设置不备份"标志.请建议我做同样事情的正确方法.
答案取决于你的数据库文件是如何创建的:
根据数据存储指南页面:
<块引用>只有用户生成的或您的应用程序无法重新创建的文档和其他数据才能存储在/Documents 目录,将自动由 iCloud 备份.
可以再次下载或重新生成的数据应存储在/Library/Caches 目录中.文件示例你应该在 Caches 目录下包含数据库缓存文件和可下载的内容,例如杂志、报纸使用的内容,和地图应用程序.
这对我来说似乎比较清楚:如果您的应用程序以编程方式创建某些内容或生成您想要保存的数据,请将其放在缓存"文件夹中.如果这是客户自己生成的独特内容(通过键盘输入或他们手动干预并执行的操作),请将其放入文档"中.
不备份"意味着文件永远不会发送到 iCloud,如果丢失,则必须从头开始重新创建(或重新安装).
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).
这篇关于我应该将 sqlite 数据库文件写入 Documents 目录还是 Library/Caches?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!