简体   繁体   English

如何将 sqlite3 数据库文件存储在应用程序的 Library 目录中?

[英]How to store the sqlite3 database file in the Library directory of an app?

Pretty much everyone and every tutorial seems to store it's private app data in the documents directory.几乎每个人和每个教程似乎都将其私有应用程序数据存储在文档目录中。

But in my image editing app I want the user to be able to use iTunes file sharing.但在我的图像编辑应用程序中,我希望用户能够使用 iTunes 文件共享。 The problem: It exposes everything in documents to the user, and he can accidentally delete important private app data folders like the SQLite database.问题:它将文档中的所有内容暴露给用户,他可能会意外删除重要的私有应用程序数据文件夹,例如 SQLite 数据库。

Apple recommends this:苹果建议这样做:

If you do not want files to be shared with the user, put them in your application's Library directory.如果您不想与用户共享文件,请将它们放在应用程序的 Library 目录中。 If none of the standard Library subdirectories are appropriate, create a private directory inside the Library directory and give it the name of your application's bundle ID.如果标准库子目录都不合适,请在库目录中创建一个私有目录,并为其提供应用程序包 ID 的名称。 You can then use that directory to store any files that are private to your application.然后,您可以使用该目录来存储您的应用程序私有的任何文件。

I have never heard of that Library directory.我从来没有听说过那个图书馆目录。 Now the question is: How can I access this directory?现在的问题是:我怎样才能访问这个目录? Where is it?它在哪里? Will it be backed up, just like the documents directory when the user syncs with iTunes?它会被备份,就像用户与 iTunes 同步时的文档目录一样吗?

Use NSLibraryDirectory in lieu of NSDocumentDirectory (in those examples you speak of) to get the library directory and then create a directory in there using NSFileManager .使用NSLibraryDirectory代替NSDocumentDirectory (在你所说的那些例子中)来获取库目录,然后使用NSFileManager在其中创建一个目录。

Read this for more information on the application directory structure.阅读this以获取有关应用程序目录结构的更多信息。 The Library directory is backed up except the Caches directory.Caches目录外, Library目录均已备份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM