2012-05-23 5 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

항상 assetURL을 보여줍니다. 괭이를 다룰 줄 알아? –

관련 문제