0

So I have an app on the App Store with a .sqlite file containing static data of about 500 records. The .sqlite file has been copied to NSDocumentDirectory, NSUserDomainMask when the application was first launched.

I am planning on releasing an update for my app and simply add about 9 new records to the existing database (no structure changes).

I tried hard to find a suitable method to do this for a minor update but couldn't... The following link: Update/Insert content into an existing Sqlite db on an iPhone app update explains a mechanism where the developer stores the app version in the DB and checks against it to decide whether to update or not...

Appreciate any ideas/assistance on how to do this! Thanks in advance!

4
  • 3
    First off, be clear: Is your DB Core Data or SQLite? Yes, Core Data uses SQLite, but they aren't the same thing. Second (if SQLite), where is your DB file. Is is read-only in the bundle, or has it been copied to read-write storage. If in the bundle, just ship a new DB. If in read-write storage, it's a simple matter to detect that you've just installed your new version and, say, copy the new records from a file in the bundle. There are a dozen different ways to determine if you've just installed your new version. Commented Dec 11, 2013 at 2:56
  • Apologies for the confusion. I have updated above. Basically it is SQLite. It is in Documents directory... Appreciate your help! Commented Dec 11, 2013 at 3:02
  • 2
    Presumably your existing "first time" logic will detect that the DB is already there and not overlay it. So you just need to somehow detect that the DB has not been updated, either by checking for one of the update records, or by checking for, eg, a marker file in Documents. Next, read records from a file in your bundle and insert the records into the DB. Then create the marker file or whatever. Try to design it so that if it fails in the middle it can re-execute without mucking things up. Commented Dec 11, 2013 at 3:08
  • You're right about the "first time" logic :). I'll try to implement this the way you described and post what I came up with. Thanks again! Commented Dec 11, 2013 at 3:12

1 Answer 1

1

As Hot Licks said,call this code after DB was initialized:

if([self isFirstLaunchInCurrentVersion]){      
    //query the records you want to add , if records not exist, then insert them 

    [self setCurrentVersionLaunch:YES];
}

two util method:

- (BOOL)isFirstLaunchInCurrentVersion{
    NSString * currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
    return  [[NSUserDefaults standardUserDefaults] boolForKey:currentVersion];
}
- (void)setCurrentVersionLaunched:(BOOL)isFirstLaunched{
    NSString * currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
    [[NSUserDefaults standardUserDefaults] setBool:isFirstLaunched forKey:currentVersion];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
Sign up to request clarification or add additional context in comments.

2 Comments

and HotLicks, I apologize: The app that I am using is a old one, and I was looking at a local version of the app that is older than the one I have submitted. It appears that at the time, I ended up submitting the one that uses CoreData... I have reposted my question here: stackoverflow.com/questions/20533014/…
Mistype: "setCurrentVersionLaunch" should be "setCurrentVersionLaunched"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.