iOS-如何构建数据库以符合iCloud备份规则



我在将应用程序提交到应用商店时遇到问题。这是因为可更新的数据库太大,无法满足iCloud备份的限制。数据库中的大多数数据都是静态的,但有一个表记录了用户复习单词的时间表(这是一个词汇测验)。

据我所知,我有两三个现实的选择。第一种是将整个数据库放入Library/Cache目录。这应该被接受,因为它没有备份到iCloud。然而,无法保证它会在应用程序更新期间得到维护,根据以下网址的"使应用程序备份更高效"中的条目:

http://developer.apple.com/library/IOs/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTuning/PerformanceTuning.html

Files Saved During App Updates
When a user downloads an app update, iTunes installs the update in a new app directory. It then moves the user’s data files from the old installation over to the new app 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.

第二个选项是将数据放入NSDocuments或NSLibrary目录中,用skipBackupFlag进行标记。然而,一个问题是,根据上"如何防止文件备份到iCloud和iTunes?"

https://developer.apple.com/library/ios/#qa/qa1719/_index.html

Important The new "do not back up" attribute will only be used by iOS 5.0.1 or later. On iOS 5.0 and earlier, applications will need to store their data in <Application_Home>/Library/Caches to avoid having it backed up. Since this attribute is ignored on older systems, you will need to insure your app complies with the iOS Data Storage Guidelines on all versions of iOS that your application supports

这意味着,即使我使用"skipBackupFlag",我仍然会遇到数据库备份到云的问题。

因此,第三种选择是将数据库一分为二,这几乎是一种丑陋的黑客攻击。将可更新部分放入NSLibrary或NSDocuments目录,其余部分留在应用程序资源中。这将把小的、可更新的部分存储在云上,剩下的留在应用程序资源目录中。问题是,这会毫无理由地拆分数据库,并在同时打开两个数据库时引入可能的性能问题。

那么,我的问题是,我对规则的解释正确吗?我会选择第三种选择吗?

附言:我在上一篇文章中注意到,被引用的网址被编辑为没有显示网址的链接。我该怎么做?

您是否考虑过使用中所述的外部文件引用https://developer.apple.com/library/IOS/#releasenotes/DataManagement/RN-CoreData/index.html。具体而言,请参阅"setAllowsExternalBinaryDataStorage:"https://developer.apple.com/library/IOS/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSAttributeDescription_Class/reference.html#//apple_ref/occ/instm/NSAttributeDescription/setAllowsExternalBinaryDataStorage:。将大数据推送到一个单独的文件中可以帮助减少数据库大小。

最新更新