2016-06-24 10 views
0

Hallo zusammen, ich benutze ALAsssetsLibrary, um Videos/Bilder in das Album zu schreiben. Aber XCode sagt mir, dass ALAssentsLibrary veraltet ist und ich muss PHPhotoLibrary verwenden, das ist alles gut und gut, aber es gibt keine Beispiele oder Dokumentation, wie man diesen Übergang macht.Wie schreibe ich ein Video/Bild in ein gespeichertes Fotoalbum mit PHPhotoLibrary?

Kann mir jemand zeigen, wie man diesen Code ändert, um PHPHotoLibrary zu verwenden?

let data:NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer) 
let image:UIImage = UIImage(data: data)! 

let library:ALAssetsLibrary = ALAssetsLibrary() 
let orientation: ALAssetOrientation = ALAssetOrientation(rawValue: image.imageOrientation.rawValue)! 
library.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation, completionBlock: nil) 

und für Video:

ALAssetsLibrary().writeVideoAtPathToSavedPhotosAlbum(outputFileURL, completionBlock: { 
     (assetURL:NSURL!, error:NSError!) in 
     if error != nil{ 
      print(error) 

     } 

     do { 
      try NSFileManager.defaultManager().removeItemAtURL(outputFileURL) 
     } catch _ { 
     } 

     if backgroundRecordId != UIBackgroundTaskInvalid { 
      UIApplication.sharedApplication().endBackgroundTask(backgroundRecordId) 
     } 

    }) 

Antwort

0

Bild Speichern:

PHPhotoLibrary.shared().performChanges({ 
    PHAssetChangeRequest.creationRequestForAsset(from: image) 
}, completionHandler: { (success, error) in 
    // completion callback 
}) 

Video:

PHPhotoLibrary.shared().performChanges({ 
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: mediaUrl as URL) 
}, completionHandler: { (success, error) in 
    // completion callback 
}) 
Verwandte Themen