更新/改写问题:
在我的项目中,我使用 ALAssetsLibrary-CustomPhotoAlbum 。虽然它在 iOS 7 上运行良好,但我从未注意到在为 iOS 8 编码时,它最终被破坏了。无法重新创建已删除的同名文件夹。
如果它作为一个新进程启动,它将创建文件夹,如果您打开应用程序并请求照片许可。
如果我手动创建文件夹,我当前的代码仍然会将照片保存到所述文件夹:
[self.library saveImage:image toAlbum:@"NamedAlbum" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(@"Big error: %@", [error description]);
}
}];
我坚持的是以下内容:
[self.library saveImage:image toAlbum:@"NamedAlbum" completion:nil failure:^(NSError *error) {
if (error!=nil) {
NSLog(@"Big error: %@", [error description]);
}
}];
它似乎改变了完成/失败 block 过程,我无法弄明白。
我需要做什么才能将它们链接到库?
如有任何帮助,我们将不胜感激。
12 月 22 日更新 似乎我在发布我的答案时超前了,这只是有时有效。将继续挖掘。
// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
if (error) NSLog(@"!!!ERROR, write the image data to the assets library (camera roll): %@",
[error description]);
NSLog(@"*** URL %@ | %@ || type: %@ ***", assetURL, image, [assetURL class]);
};
void (^failure)(NSError *) = ^(NSError *error) {
if (error == nil) return;
NSLog(@"!!!ERROR, failed to add the asset to the custom photo album: %@", [error description]);
};
[self.assetsLibrary saveImage:image
toAlbum:albumName
completion:completion
failure:failure];
最佳答案
虽然我确实相信 SDK 中存在错误。我下面的内容似乎在我的 6+ 上运行良好。
这可能不是“正确”的方法,但它是所提供的示例中有效的方法。
NSURL *imageURL = receivedURL;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
NSString *albumName = @"NamedAlbum";
// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
if (error) NSLog(@"!!!ERROR, write the image data to the assets library (camera roll): %@",
[error description]);
NSLog(@"*** URL %@ | %@ || type: %@ ***", assetURL, image, [assetURL class]);
};
void (^failure)(NSError *) = ^(NSError *error) {
if (error == nil) return;
NSLog(@"!!!ERROR, failed to add the asset to the custom photo album: %@", [error description]);
};
[self.library saveImage:image
toAlbum:albumName
completion:completion
failure:failure];
希望这对某人有帮助,尽管很遗憾这个问题被否决了。
关于ios - ALAssetsLibrary-自定义相册 ios 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27585750/