0

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

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]);
            }
        }];
4

1 回答 1

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
}
于 2013-05-23T14:46:41.413 回答