English 中文(简体)
将视频保存到相机滚动中的自定义相册
原标题:Save video to custom album in camera roll

我能够将图像保存到 iPhone 相机滚动中的自定义相册中。 例如, 相册名称可以是“ Fun ”, 我拍摄的所有图像都会放入该文件夹。 我遇到了一个帮手班< a href=' http://www.touch- code-magazine.com/ ios5- savec- photos- in- custom- photo- album- 类以下载/ “ rel=“ no follown” >, 这里非常适合完成我想要完成的任务 。

然而,我所使用的方法并没有将视频保存到自定义文件夹中,但是创建了文件夹 - 它只是空的视频, 我试图保存在那里。 我尝试了调试它, 但没有进展。 这个方法在这里 :

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

                   时 时];

时 时





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签