7

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?

Sam Bing
  • 2,794
  • 1
  • 19
  • 29
  • Maybe by storing the NSData (converting it into jpg/mov if needed) and use the same method? – Larme Feb 23 '16 at 17:28
  • 1
    Would converting them require saving them to disk?(Which i dont want, at least not permanently), since the function requires i provide the path to the file. – Sam Bing Feb 23 '16 at 21:58
  • You can save them into a temporary folder that you delete after while. But it seems that PHLivePhoto need two URLs, so that seems the only way to do it. – Larme Feb 23 '16 at 22:11
  • Seems like it. I'll give it a try, thanks. – Sam Bing Feb 24 '16 at 07:14

0 Answers0