从App Store更新应用程序时,保存在NSDocumentDirectory中的图像已消失

时间:2013-04-03 03:35:54

标签: iphone ios file nsdocumentdirectory

图像保存为以下代码:

-(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;
    }
 }

据我所知,当从App Store更新应用程序时,不会清除保存在NSDocumentDirectory中的图像,但事实是这些图像已经消失。这是怎么回事?

0 个答案:

没有答案