2010-10-03 8 views
4

Y a-t-il un moyen pour enregistrer une vidéo dans le répertoire Documents de la bibliothèque de photos? J'ai le lien de la vidéo dans le répertoire des documents, je ne sais pas comment l'enregistrer dans l'application Photos.Enregistrement d'une vidéo dans la bibliothèque de photos - SDK iPhone

Merci,

Kevin

+0

Vous devez également ajouter à NSPhotoLibraryUsageDescription Info.plist: http://stackoverflow.com/questions/39519773/nsphotolibraryusagedescription-key-must-be-present-in-info-plist-to-use -caméra-r –

Répondre

6

Si vous enregistrez dans un répertoire local, vous pouvez l'enregistrer comme ..

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; 
    [assetLibrary writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error){ 
     if(error) { 
      NSLog(@"error while saving to camera roll %@",[error localizedDescription]);   
     } else { 
      //For removing the back up copy from the documents directory   
      NSError *removeError = nil; 
      [[NSFileManager defaultManager] removeItemAtURL:url error:&removeError]; 
      NSLog(@"%@",[removeError localizedDescription]); 
     } 
    }]; 
0

Essayez cette

Vous pouvez également utiliser ce code pour télécharger et sauvegarder des fichiers vidéo à partir d'Internet aux photos.

NSURL *videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"Your Video Url or Path"]]; 

dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); 
dispatch_async(q, ^{ 

    NSData *videoData = [NSData dataWithContentsOfURL:videoUrl]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 

     // Write it to cache directory 
     NSString *videoPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"file.mov"]; 
     [videoData writeToFile:videoPath atomically:YES]; 

     // After that use this path to save it to PhotoLibrary 
     ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
     [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath] completionBlock:^(NSURL *assetURL, NSError *error) 
     { 
      if (error) 
      { 
       NSLog("Error"); 
      } 
      else 
      { 
       NSLog("Success"); 
      } 

     }]; 
    }); 
}); 
Questions connexes