繁体   English   中英

将视频保存到相机胶卷中的自定义相册

[英]Save video to custom album in camera roll

我可以将图像保存到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];

}

有谁知道将视频保存到照片库中自定义相册中的正确方法?

试试这个,对我有用。

-(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];

                   }];

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM