iOS app update, how to update plist in the bundle?
Asked Answered
C

3

5

Is there a way to update a modified plist file that's in the bundle through an iTunes app update?

I have an app that stores some data in a plist file in the form of an array & dictionaries. On some updates I have added to the plist file with more array items, but it seems that when the app is updated, the new plist file isn't copied/updated over unless the user deletes the app and re-installs it.

How do I get the app to update the local copy of the plist file with the new one?

Chretien answered 14/4, 2011 at 17:0 Comment(0)
V
6

You can't update anything that's part of the bundle. Save the plist in the documents directory if you want to be able to update it.

NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
        NSUserDomainMask, YES);
NSString *documentsDirectory = [arrayPaths objectAtIndex:0];

Files in the documents directory don't get deleted when updating an app using the store.

Vowelize answered 14/4, 2011 at 17:3 Comment(2)
So, if I move my updated plist file via code to the documents directory, will it over-write/update any existing plist file that's there?Chretien
Only if one exists with the same name and you choose to overwrite it using the appropriate NSFileManager methods.Vowelize
S
2

Versioned .plist files? E.g. MyApp-YYYYMMdd.plist

Seaman answered 14/4, 2011 at 17:14 Comment(0)
L
1

I had a similar issue in an app. What I did to address is it check whether the app has loaded the old or the new version of the plist file when the app gets the willEnterForeground notification in the app delegate, and then load the new file from the bundle and save it to the documents directory.

Loudermilk answered 14/4, 2011 at 18:39 Comment(2)
How did you go about checking versions?Chretien
In my case that was easy because there was date-based data in the files.Loudermilk

© 2022 - 2024 — McMap. All rights reserved.