保存到自定义照片文件夹IOS 7.1

时间:2013-05-22 21:57:03

标签: objective-c uiimage alassetslibrary

保存图像时有没有办法禁用“已保存的照片”文件夹?

NSData *data1 = UIImagePNGRepresentation(imageToCrop.image);
        UIImage *tehnewimage = [UIImage imageWithData: data1];
        [self.library saveImage:tehnewimage toAlbum:@"Databender Edits"     withCompletionBlock:^(NSError *error) {
            if (error!=nil) {
                NSLog(@"eRrOr: %@", [error description]);
            }
        }];

1 个答案:

答案 0 :(得分:1)

如果您使用ALAssetsLibrary来管理您的应用照片,那么它们将始终显示在已保存的照片下。根据Apple Docs,ALAssetsLibrary的目的是

You use it to retrieve the list of all asset groups and to save images and videos into the Saved Photos album.

如果您只需要在应用程序内部访问您的图像,您可以处理阅读写作,并自己呈现。这样可以防止它们出现在相机角色或保存的照片中。

 //WRITING TO APP DIRECTORY
 NSString *directory = [NSHomeDirectory() stringByAppendingPathComponent:@"Photos/"];

if (![[NSFileManager defaultManager] fileExistsAtPath:directory]){
    NSError* error;
    [[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error];
}
NSData *imgData = UIImagePNGRepresentation(imageToCrop.image);
NSString *imgName = @"example.png";
NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:imgName];
[imgData writeToFile:pngPath atomically:YES]; 

//READING FROM APP DIRECTORY
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"/Photos/"] error:NULL];
for (int i = 0; i < (int)[directoryContent count]; i++)
{
    NSURL *url = [NSURL URLWithString:[NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"/Documents/Photos/%@",[directoryContent objectAtIndex:i]]]];
    UIImage *image = [UIImage imageWithContentsOfFile:[url absoluteString]];
    //ADD IMAGE TO TABLE VIEW OR HANDLE HOW YOU WOULD LIKE
}