I'm getting ready to release a new update for my app which stores data in the local bundle path and I want to ensure the data stored in this path isn't deleted when they update. Can this happen and what should I watch out for?
This is the code I'm using to get the path to store data:
// Temporary method variables
NSError *error;
// Create a list of paths
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// Get the path to the apps documents directory from the array
NSString *documentsDirectory = [paths objectAtIndex:0];
// Create a full path to the file
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"FFUserPrefs.plist"];
// Access the file manager
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the file exists and if not, copy from the bundle path to the documents path
if (![fileManager fileExistsAtPath:path])
{
// Get path to file from bundle directory
NSString *pathBundle = [[NSBundle mainBundle] pathForResource:@"FFUserPrefs" ofType:@"plist"];
// Copy pref file to app documents folder
[fileManager copyItemAtPath:pathBundle toPath:path error:&error];
}
I'm just afraid that the data my users have stored in this directory could be lost and want to make sure it is still there after updating. The only reason I ask is because after running my new build via xCode on my phone that had the release application installed, it wiped out the data and started fresh. What am I missing? Does the app bundle path change between Xcode and release. Any info would be greatly appreciated!
Files stored in the documents directory will not be removed during an app update. FFUserPrefs.plist
is stored in the documents directory, so it will still be there after the update. Files stored in the app bundle ([NSBundle mainBundle]
), however, will be replaced by the new bundle.