2012-05-23 100 views
0

我可以將圖像保存到iPhone相機膠捲中的自定義相冊中。例如,專輯名稱可能是「有趣」,我所拍攝的所有圖像都將進入該文件夾。我遇到了一個幫手類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]; 

} 

有誰知道將視頻保存到照片庫中的自定義相冊的正確方法?

+0

您的代碼看起來像從http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download /。 這個腳本仍然不穩定(請閱讀該頁面的評論) –

回答

0

試試這個,它適合我。

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

        }]; 

}

+0

它總是顯示nil assetURL。鋤頭來處理它? –

相關問題