2016-12-01 8 views
0

У меня есть более 10 видеороликов в одном представлении, которое поступает из веб-сервиса. Я показываю эти миниатюры в виде таблицы. Я использую следующий код, где я м Сохранение этих видео в галерею в определенной папкеКак сохранить видео в папке Partcular в Iphone Gallery в objctive c

Это мой код ::

NSURL *url = [NSURL URLWithString:Urlstr]; 
NSData *data = [NSData dataWithContentsOfURL:url]; 

// Write it to cache directory 
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"file.mov"]; 
[data writeToFile:path atomically:YES]; 
// After that use this path to save it to PhotoLibrary 
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
[library addAssetsGroupAlbumWithName:@"MyFolderName" resultBlock:^(ALAssetsGroup *group) 
{ 
    //How to get the album URL? 
    // saving the video in gallery though file path and document directory 
    [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError *error) { 

     if (error) { 
      NSLog(@"%@", error.description); 
     }else { 
      NSLog(@"Done :)"); 
     } 
    }]; 
} 
    failureBlock:^(NSError *error) { 
          //Handle the error 
         }]; 

Теперь вопросы это не спасает мое видео в мою папку. но он создает папку и сохраняет видео в папке видео по умолчанию в галерее. Кто-нибудь, пожалуйста, предложите мне, почему так происходит.

+0

Почему бы вам не использовать или получить подсказку от https://github.com/Kjuly/ALAssetsLibrary-CustomPhotoAlbum – Poles

+0

HII полюсов .. я реализовал это. но это дает много ошибок. – user6898211

+0

Какие ошибки вы получаете? – Poles

ответ

1
- (void)createAlbumInPhotosLibrary:(NSString *)photoAlbumName videoAtFile:(NSURL *)videoURL { 

    // RELIVIT_moments 
    __block PHFetchResult *photosAsset; 
    __block PHAssetCollection *collection; 
    __block PHObjectPlaceholder *placeholder; 

     // Find the album 
     PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init]; 
     fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", photoAlbumName]; 
     collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum 
                   subtype:PHAssetCollectionSubtypeAny 
                   options:fetchOptions].firstObject; 
     // Create the album 
     if (!collection) 
     { 
      [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
      PHAssetCollectionChangeRequest *createAlbum = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:photoAlbumName]; 
      placeholder = [createAlbum placeholderForCreatedAssetCollection]; 

     } completionHandler:^(BOOL success, NSError *error) { 

       if (success) 
       { 
       PHFetchResult *collectionFetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[placeholder.localIdentifier] 
                               options:nil]; 
       collection = collectionFetchResult.firstObject; 

       [self saveVideoInRelivitFolderSetPlaceHolder:placeholder photosAsset:photosAsset collection:collection VideoAtFile:videoURL]; 

       } 

      }]; 

     } else { 

      [self saveVideoInRelivitFolderSetPlaceHolder:placeholder photosAsset:photosAsset collection:collection VideoAtFile:videoURL]; 
     } 

} 

- (void)saveVideoInRelivitFolderSetPlaceHolder:(PHObjectPlaceholder *)placeholderLocal photosAsset:(PHFetchResult *)photosAssetLocal collection:(PHAssetCollection *)collectionLocal VideoAtFile:(NSURL *)videoURL { 

     __block PHFetchResult *photosAsset = photosAssetLocal; 
     __block PHAssetCollection *collection = collectionLocal; 
     __block PHObjectPlaceholder *placeholder = placeholderLocal; 

     // Save to the album 
     [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
      PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:videoURL]; 
      placeholder = [assetRequest placeholderForCreatedAsset]; 
      photosAsset = [PHAsset fetchAssetsInAssetCollection:collection options:nil]; 

      PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection 
                                  assets:photosAsset]; 
      [albumChangeRequest addAssets:@[placeholder]]; 

     } completionHandler:^(BOOL success, NSError *error) { 
      if (success) 
      { 
       NSLog(@"done"); 
      } 
      else 
      { 
       NSLog(@"%@", error.localizedDescription); 
      } 
     }]; 

} 
+0

аналогичный или простой вопрос с большой щедростью. Http://stackoverflow.com/questions/43791151/100-bounty-actually-get-the-filename-of-image-saved-to-photos-album-2017-ios10 – Fattie

 Смежные вопросы

  • Нет связанных вопросов^_^