0

I released an app that the user can edit some pictures and save it on the own app (I mean: it is not saved on camera roll). Sometime after, I released the version 2.0 of the app and the users complained the update process deleted their saved pictures.

It follows part of my code where the pictures are saved:

NSData *dataFromPNG = UIImagePNGRepresentation(image);
NSString *mainPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/SavedData"];
NSString *directory = [mainPath stringByAppendingPathComponent:[NSString stringWithFormat:@"image(%d).png", imageIndex]];
[dataFromPNG writeToFile:directory atomically:YES];

Where is my mistake?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

How you are calculating your imageIndex ? I think, problem is there. If they have saved 10 images with last version, then are you calculating last index with new version?

I think, you are overwriting images, so it seems that update is deleting. It was a guess with code you provided. Try this and if its not the solution, provide your code to calculate imageIndex.

halfer
  • 19,824
  • 17
  • 99
  • 186
Bhanupriya
  • 1,202
  • 1
  • 9
  • 20
  • When the app is opened, the system reads all saved pictures, put them on a UICollectionView and counts the number of picture. So, When the user creates a new picture, indexPicture is the number of pictures + 1. – Jeff McIntosh Jul 03 '15 at 16:04
  • Where are you storing? NSCachesDirectory or NSDocumentDirectory? Check this link : http://stackoverflow.com/questions/6879860/when-are-files-from-nscachesdirectory-removed – Bhanupriya Jul 07 '15 at 05:07
  • I don't know how to answer it. According with this line of my code: `NSString *mainPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/SavedData"];`, I believe I am using NSDocumentDirectory. – Jeff McIntosh Jul 19 '15 at 23:01