我的iPhone应用程序应该在哪里存储SQLite DB ?

时间:2021-02-17 04:17:55

I have several iOS apps on the market and in all of them I have a small SQLite database file connected to the app to provide the user with my data. Once installed the user customizes this DB by changing certain options.

我在市场上有几款iOS应用,其中有一个小的SQLite数据库文件连接到应用上,为用户提供我的数据。一旦安装了用户,用户通过改变某些选项来定制这个数据库。

Until now, all of these apps store the DB in NSDocumentsDirectory. After submitting my last update, it was rejected for storing data in the wrong location. For the apps rejected I changed the storage location to NSCachesDirectory. I am now afraid that the cache will get cleared and erase the users customizations. The app would still function, the DB would get recreated, but all changed tables would be reset, thereby upsetting users.

到目前为止,所有这些应用程序都将DB存储在NSDocumentsDirectory中。在提交上次更新后,它被拒绝了,因为它将数据存储在错误的位置。对于被拒绝的应用程序,我将存储位置更改为NSCachesDirectory。我现在担心缓存将被清除并删除用户自定义。应用程序仍然可以运行,DB将被重新创建,但是所有更改的表将被重新设置,从而使用户感到不安。

Where should this type of database file be stored? Was I right to put it in the Docs dir? According to Apple, the Docs dir is for "Critical Data" which is either user generated data or data needed for proper operation of the app. I feel that it falls under that category, persisting my users settings is proper operation, but who wants to await an appeal?

这种类型的数据库文件应该存储在哪里?我把它放在文档目录是对的吗?根据苹果公司的说法,Docs dir是针对“关键数据”,即用户生成的数据或应用正常运行所需要的数据。我认为它属于这一范畴,坚持我的用户设置是正确的操作,但谁愿意等待上诉呢?

3 个解决方案

#1


31  

Apple's file system programming guide for iOS describes the (application_home)/Library path as a place to "create custom subdirectories for files you want backed up but not exposed to the user". The (application_home)/Documents path is described as "the contents of this directory can be made available to the user through file sharing."

苹果iOS的文件系统编程指南将(application_home)/库路径描述为“为需要备份但不向用户公开的文件创建自定义子目录”的地方。(application_home)/Documents路径被描述为“可以通过文件共享向用户提供该目录的内容”。

Your databases don't sound like documents, they sound like private caches that users shouldn't know about. I recommend you create a directory such as (application_home)/Library/Database and save files there. The cache path you mention doesn't sound like the best option to me.

您的数据库听起来不像文档,它们听起来像用户不应该知道的私有缓存。我建议您创建一个目录,例如(application_home)/Library/Database,并在其中保存文件。你提到的缓存路径对我来说不是最好的选择。

You should really review the entire file system programming guide for iOS before submitting another app.

在提交另一个应用程序之前,您应该仔细阅读iOS的整个文件系统编程指南。

#2


0  

If your database indeed contains user-generated content, then the Documents directory is its proper location.

如果您的数据库确实包含用户生成的内容,那么文档目录就是它的正确位置。

However, you mention that you are persisting "your users settings"... If the data you are persisting are more akin to settings or preferences, then they should reside in the Defaults subsystem. See the documentation for NSUserDefaults.

但是,您提到您正在持久化“您的用户设置”……如果您要持久化的数据更类似于设置或首选项,那么它们应该位于默认子系统中。请参阅NSUserDefaults的文档。

#3


0  

6 year update:

更新:6年

Storing the data in the NSCachesDirectory caused a bug, as expected, that the users customized data would erase whenever the device felt like it. After many many attempts at arguing the point with Apple app review, I was able to finally post an update where the data is now stored in a custom directory in the NSDocumentsDirectory (as it should be) which solved all of the aforementioned issues.

在NSCachesDirectory中存储数据会导致一个错误,正如预期的那样,用户自定义数据会在设备需要时删除。在与Apple app review就这一点进行了多次争论之后,我终于发布了一个更新,现在数据存储在NSDocumentsDirectory中的自定义目录中(应该是这样),它解决了上述所有问题。

#1


31  

Apple's file system programming guide for iOS describes the (application_home)/Library path as a place to "create custom subdirectories for files you want backed up but not exposed to the user". The (application_home)/Documents path is described as "the contents of this directory can be made available to the user through file sharing."

苹果iOS的文件系统编程指南将(application_home)/库路径描述为“为需要备份但不向用户公开的文件创建自定义子目录”的地方。(application_home)/Documents路径被描述为“可以通过文件共享向用户提供该目录的内容”。

Your databases don't sound like documents, they sound like private caches that users shouldn't know about. I recommend you create a directory such as (application_home)/Library/Database and save files there. The cache path you mention doesn't sound like the best option to me.

您的数据库听起来不像文档,它们听起来像用户不应该知道的私有缓存。我建议您创建一个目录,例如(application_home)/Library/Database,并在其中保存文件。你提到的缓存路径对我来说不是最好的选择。

You should really review the entire file system programming guide for iOS before submitting another app.

在提交另一个应用程序之前,您应该仔细阅读iOS的整个文件系统编程指南。

#2


0  

If your database indeed contains user-generated content, then the Documents directory is its proper location.

如果您的数据库确实包含用户生成的内容,那么文档目录就是它的正确位置。

However, you mention that you are persisting "your users settings"... If the data you are persisting are more akin to settings or preferences, then they should reside in the Defaults subsystem. See the documentation for NSUserDefaults.

但是,您提到您正在持久化“您的用户设置”……如果您要持久化的数据更类似于设置或首选项,那么它们应该位于默认子系统中。请参阅NSUserDefaults的文档。

#3


0  

6 year update:

更新:6年

Storing the data in the NSCachesDirectory caused a bug, as expected, that the users customized data would erase whenever the device felt like it. After many many attempts at arguing the point with Apple app review, I was able to finally post an update where the data is now stored in a custom directory in the NSDocumentsDirectory (as it should be) which solved all of the aforementioned issues.

在NSCachesDirectory中存储数据会导致一个错误,正如预期的那样,用户自定义数据会在设备需要时删除。在与Apple app review就这一点进行了多次争论之后,我终于发布了一个更新,现在数据存储在NSDocumentsDirectory中的自定义目录中(应该是这样),它解决了上述所有问题。