发布应用更新时,捆绑路径中的数据是否会更改或被删除?

时间:2012-12-31 02:44:30

标签: iphone ios nsbundle

我正准备为我的应用程序发布一个新的更新,该更新将数据存储在本地捆绑包路径中,并且我希望确保更新时不会删除存储在此路径中的数据。这可能发生吗?我应该注意什么?

这是我用来获取存储数据路径的代码:

// 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];
}

我只是担心用户存储在此目录中的数据可能会丢失,并且确保在更新后仍然存在。我问的唯一原因是因为在安装了发布应用程序的手机上通过xCode运行我的新版本之后,它会清除数据并重新开始。我错过了什么?应用程序包路径是否在Xcode和发布之间发生变化。任何信息将不胜感激!

1 个答案:

答案 0 :(得分:1)

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