views:

55

answers:

1

Hi, I'm working on an update for an already existing iphone app. The existing version contains a .sql database file which is used in the app.

I would like to use a new version of this file in the update of the app. On the first startup of the existing app the .sql file is placed in the caches directory of the users iphone. From what I can understand from Apple's documentation the files in the caches directory might get copied from the old app to the new versions caches directory when the user updates the app. Does this mean that for being sure my new file is used in the updated version I should use a different name of the file?

And what happens with the old file? Do I have to manually delete it from inside the app? Which means I have to check if it's there at every startup of the app?

Thanks Michael

A: 

Yes, you could use a different name, or you could use the same name, and do an "upgrade" (delete and replace) on the first time the user uses a new version.

This does imply checking at every app start, but that's not a bad idea anyways. Having some code that checks versioning at app start lets you put any data upgrade stuff in one place.

One technique is to use NSUserDefaults to keep around two pieces of information: the originally installed version of the app, and the most recently run version of the app. You check these at startup. If they're not there, write both of them. If the most-recent version is lower than the running app version, run your upgrades and bump the version. You could use the first flag to know conditionally in other places whether to expect certain data to be sitting around or not. Having versioning stored explicitly lets you know which version you're upgrading from, too, which might not be obvious if the user hasn't downloaded say 5 intervening updates.

quixoto
That's a nice solution! In that case I won't be having any old files taking up space. Actually, I'm already checking the version numbers exactly as you described, I just didn't think of replacing the old file with the new one. Thanks!
Michael Frost