【发布时间】:2012-05-30 02:55:47
【问题描述】:
我可以将图像保存到 iPhone 相机胶卷中的自定义相册中。例如,相册名称可以是“Fun”,我拍摄的所有图像都会进入该文件夹。我遇到了一个帮助类here,它可以很好地完成我想要的。
但是,我使用的方法不会将视频保存到自定义文件夹中,而是创建了该文件夹 - 它只是没有我尝试保存的任何视频。我尝试调试它没有任何进展。方法在这里:
-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;
//search all photo albums in the library
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
//compare the names of the albums
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
//target album is found
albumWasFound = YES;
NSData *data = [NSData dataWithContentsOfURL:assetURL];
if ([data length] > 0) {
//get a hold of the photo's asset instance
[self assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
[group addAsset: asset];
//run the completion block
completionBlock(nil);
} failureBlock: completionBlock];
}
//album was found, bail out of the method
return;
}
if (group==nil && albumWasFound==NO) {
//photo albums are over, target album does not exist, thus create it
__weak ALAssetsLibrary* weakSelf = self;
//create new assets album
[self addAssetsGroupAlbumWithName:albumName
resultBlock:^(ALAssetsGroup *group) {
//get the photo's instance
[weakSelf assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
NSLog(@"asset: %@",asset);
//add photo to the newly created album
[group addAsset: asset];
//call the completion block
completionBlock(nil);
} failureBlock: completionBlock];
} failureBlock: completionBlock];
//should be the last iteration anyway, but just in case
return;
}
} failureBlock: completionBlock];
}
有谁知道将视频保存到照片库的自定义相册中的正确方法?
【问题讨论】:
-
您的代码看起来像是来自 touch-code-magazine.com/… 。此脚本仍然不稳定(请阅读该页面中的 cmets)
标签: ios ios5 video alassetslibrary