1

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!

4

1 回答 1

1

应用程序更新期间不会删除存储在文档目录中的文件。FFUserPrefs.plist存储在文档目录中,因此更新后它仍然存在。但是,存储在 app bundle ( [NSBundle mainBundle]) 中的文件将被新的 bundle 替换。

于 2012-12-31T02:53:36.090 回答