I am creating an to-do list iphone app and facing a problem related to version update.
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. When the app starts, it executes “CREATE IF EXISTS MY_TABLE” so I can guarantee there’s a usable database table.
Edited:
thanks @JP reply, my issue is solved by modifying like:
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>/Documentsdirectory, the file will be backed up by iTunes and kept across app updates.Details are in the iOS Application Programming Guide in sections “Backup and Restore” and “A Few Important Application Directories”