-1

I have an app that stores images from the user in the app/documents folder, I'm doing the following code determine the path to save it:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docs = [paths objectAtIndex:0];
    NSString *imageFilename = [[[[NSNumber alloc] initWithInteger:self.nextID] stringValue] stringByAppendingFormat:@".jpg"];
    NSString *dirPath = [docs stringByAppendingFormat:@"/Photos/"];
    imagePath = [dirPath stringByAppendingString:imageFilename];

it gives me a path similar to (in simulator): /var/mobile/Applications/C9C43CFD-6A5F-40CF-8BAE-20496B5A544A/Documents/Photos/1.jpg

I save this path to show this image when I need.

My problem is, when I sent an update in the app store, after update the app it cant show the images anymore. My understand is the Documents folder cant change when update the app in AppStore.

My probably reason for that it the name between Applications folder and Documentar has changed, is it true when update a app version from AppStore?

Does anyone has any idea? is there any way to test this app update local?

Thanks

4

2 回答 2

1

您需要在Documents目录之后保存相对路径,而不是绝对路径。应用程序的目录可以在更新期间更改,但应用程序沙箱内的结构不会更改。

此外,还有一种更好的构建路径的方法:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString *imageFilename = [NSString stringWithFormat:@"%d.jpg", self.nextID];
NSString *dirPath = [docs stringByAppendingPathComponent:@"Photos"];
imagePath = [dirPath stringByAppendingPathComponent:imageFilename];
于 2013-04-30T21:11:27.797 回答
0

当应用程序从 App Store 更新时,Documents 目录的内容不会改变。应用程序包及其所有内容都将替换为新版本,但 Documents 文件夹是在应用程序版本之间存储内容的安全位置。

于 2013-04-30T20:57:43.750 回答