Live Photo From NSData

1k Views Asked by At

I store live photos on the server as they come, with two separate files a JPG, and MOV file. When i retrieve them i am left with NSData, which is where my issue arises, i don't know how to create a PHLivePhoto out of that data.

Here is how i create an PHLivePhoto if the files are bundled up in my project:

let imgURL = NSBundle.mainBundle().URLForResource("IMG_0001", withExtension: "JPG")!
let movURL = NSBundle.mainBundle().URLForResource("IMG_0001", withExtension: "mov")!

func makeLivePhotoFromItems(imageURL: NSURL, videoURL: NSURL, previewImage: UIImage, completion: (livePhoto: PHLivePhoto) -> Void) {
    PHLivePhoto.requestLivePhotoWithResourceFileURLs([imageURL, videoURL], placeholderImage: previewImage, targetSize: CGSizeZero, contentMode: PHImageContentMode.AspectFit) {
        (livePhoto, infoDict) -> Void in
        // for debugging: print(infoDict)
        if let lp = livePhoto {
            completion(livePhoto: lp)
        }
    }
}

 //  Credit :
   http://stackoverflow.com/questions/33990830/working-with-live-photos-in-playground

This gives me a PHLivePhoto. What approach should i take to display the photos to the user?

0

There are 0 best solutions below