简体   繁体   English

安装较新版本后保留sqlite数据库

[英]Keep sqlite database after installing newer version

I am creating an to-do list iphone app and facing a problem related to version update. 我正在创建待办事项清单iPhone应用程序,并且遇到与版本更新相关的问题。

During each Build & Debug process, I discovered that the my last testing data is all gone. 在每个“构建与调试”过程中,我发现我最后的测试数据都已耗尽。 It's fine for development and testing but how about once the app is published and when I publish a new version update? 开发和测试都很好,但是一旦发布应用程序以及当我发布新版本更新时如何? I would like my users to keep their previously to-do list. 我希望我的用户保留以前的工作清单。

I am using sqlite3.h to manipulate the database. 我正在使用sqlite3.h来操纵数据库。 When the app starts, it executes "CREATE IF EXISTS MY_TABLE" so I can guarantee there's a usable database table. 当应用启动时,它会执行“ CREATE IF EXISTS MY_TABLE”,因此我可以保证存在可用的数据库表。

Edited: thanks @JP reply, my issue is solved by modifying like: 编辑:谢谢@JP答复,我的问题已通过修改来解决,例如:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filename = @"todo.db";
NSString *filepath = [documentsDirectory stringByAppendingPathComponent:filname];

previously, my code is: 以前,我的代码是:

NSString *filename = @"todo.db";
NSString *filepath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:filname];

As long as you are creating the sqlite database in the <Application_Home>/Documents directory, the file will be backed up by iTunes and kept across app updates. 只要您在<Application_Home>/Documents目录中创建sqlite数据库,该文件就会由iTunes备份并在应用程序更新中保留。

Details are in the iOS Application Programming Guide in sections "Backup and Restore" and "A Few Important Application Directories" 有关详细信息,请参阅《 iOS应用程序编程指南》的“备份和还原”“一些重要的应用程序目录”部分。

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

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