我可以将图像保存到 iPhone 相机胶卷中的自定义相册中。例如,相册名称可以是“Fun”,我拍摄的所有图像都会进入该文件夹。我在这里遇到了一个帮助类,它可以很好地完成我想要的。
但是,我使用的方法不会将视频保存到自定义文件夹中,而是创建了该文件夹 - 它只是没有我尝试保存在那里的任何视频。我尝试调试它没有任何进展。该方法在这里:
-(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];
}
有谁知道将视频保存到照片库中的自定义相册的正确方法?