3

The Image is saved as following codes:

-(NSString *)saveImage:(UIImage *)image withName:(NSString *)name{
    [self createDataPath];
    NSString *filePath = [dataPath stringByAppendingPathComponent:name];
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0f);
    [imageData writeToFile:filePath atomically:YES];
    return filePath;
}

-(void)createDataPath{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    dataPath = [[[paths objectAtIndex:0]
                stringByAppendingPathComponent:@"MyPhotos"]
            stringByAppendingPathComponent:imageUniqueId];

    /* check for existence of cache directory */
    if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
        return;
    }

    NSError *error;

    /* create a new cache directory */
    if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath
                               withIntermediateDirectories:YES
                                                attributes:nil
                                                     error:&error]) {
    //URLCacheAlertWithError(error);
    return;
    }
 }

As I know the Image saved in the NSDocumentDirectory will not be cleaned when the App updated from App Store, but the fact is these images are gone. What's going on here?

lu yuan
  • 7,207
  • 9
  • 44
  • 78
  • What is `imageUniqueId` ? – Midhun MP Apr 03 '13 at 03:44
  • @MidhunMP A random string – lu yuan Apr 03 '13 at 03:45
  • How did you retrieve those images ? – Midhun MP Apr 03 '13 at 03:52
  • @MidhunMP myImage = [UIImage imageWithData:[NSData dataWithContentsOfFile:myImagePath]]; – lu yuan Apr 03 '13 at 03:55
  • From where did you get the myImagePath, because in your path contains a random string. Then how did you take that path ? – Midhun MP Apr 03 '13 at 04:03
  • @MidhunMP the path is stored in the coredata – lu yuan Apr 03 '13 at 04:04
  • Are you storing the full path or CoreData? – Marcelo Apr 03 '13 at 04:08
  • @luyuan: that's the issue. When you update your app the data in the document directory will be there, but the name of application folder will be renamed. So your code won't work. It's better to save the unique folder name and use the NSFileManager to find the data using this information – Midhun MP Apr 03 '13 at 04:13
  • Are you sure, you have updated the app, without deleting it? Updating app will never remove any thing, while deleting and downloading new app will remove all the data.. – iphonic Apr 03 '13 at 04:15
  • Then definitely it is the image you saved by some name, doesn't exist in your database, or, something.. You can test the behavior on simulator, by checking the documents directory, by running the old project, then running the new project make sure the app-id are same in both the projects.. All the best – iphonic Apr 03 '13 at 04:22

0 Answers0