是否有办法在保存图像时禁用"已保存的照片"文件夹?
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]);
}
}];
如果你正在使用alassetlibrary来管理你的应用程序照片,那么它们将始终显示在保存的照片下。根据苹果文档,alassetlibrary的目的是
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
}