3

图像保存为以下代码:

-(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 中的图像不会被清除,但事实是这些图像已经消失了。这里发生了什么?

4

0 回答 0