【问题标题】:Save video to custom album in camera roll将视频保存到相机胶卷中的自定义相册
【发布时间】: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];

}

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

【问题讨论】:

标签: ios ios5 video alassetslibrary


【解决方案1】:

试试这个,它对我有用。

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

                   }];

}

【讨论】:

    猜你喜欢
    • 2016-05-01
    • 2015-01-06
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多