将视频保存到相机胶卷中的自定义相册 [英] Save video to custom album in camera roll
问题描述
我可以将图像保存到iPhone相机胶卷中的自定义相册中。例如,专辑名称可能是Fun,我拍摄的所有图像都将进入该文件夹。我遇到了一个帮助班这里非常适合完成我想要的工作。
I am able to save an image into a custom album in the iPhone camera roll. For example, the album name could be "Fun", and all of the images I take will go into that folder. I came across a helper class here that works very well to accomplish what I want.
但是,我使用的方法不会将视频保存到自定义文件夹中,但是文件夹已创建 - 它只是我尝试保存的任何视频的空白。我尝试调试它没有任何进展。该方法在这里:
However, the method I am using does not save videos into the custom folder, but the folder is created - it's just empty of any videos that I attempt to save there. I tried debugging it with no progress. That method is 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];
}
有谁知道将视频保存到的正确方法照片库中的自定义相册?
Does anyone know the proper way to save a video into a custom album in the photo library?
推荐答案
试试这个,它对我有用。
Try this, it works for me.
-(void)saveVideo:(NSURL *)videoUrl toAlbum:(NSString*)albumName withCompletionBlock: (SaveImageCompletion)completionBlock
{
//write the image data to the assets library (camera roll)
[self writeVideoAtPathToSavedPhotosAlbum:videoUrl completionBlock:^(NSURL* assetURL, NSError* error) {
//error handling
if (error!=nil) {
completionBlock(error);
return;
}
//add the asset to the custom photo album
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}];
}
这篇关于将视频保存到相机胶卷中的自定义相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!