NSURL from PHAsset

Paul Cezanne picture Paul Cezanne · Sep 24, 2014 · Viewed 27.8k times · Source

I'm converting our app over to use the Photos Framework of iOS8, the ALAsset framework is clearly a second class citizen under iOS8.

I'm having a problem is that our architecture really wants an NSURL that represents the location of the media on "disk." We use this to upload the media to our servers for further processing.

This was easy with ALAsset:

    ALAssetRepresentation *rep = [asset defaultRepresentation];
    self.originalVideo = rep.url;

But I'm just not seeing this ability in PHAsset. I guess I can call:

    imageManager.requestImageDataForAsset

and then write it out to a temp spot in the file system but that seems awfully heavyweight and wasteful, not to mention potentially slow.

Is there a way to get this or am I going to have refactor more of my app to only use NSURLs for iOS7 and some other method for iOS8?

Answer

jlw picture jlw · Oct 1, 2014

If you use [imageManager requestAVAssetForVideo...], it'll return an AVAsset. That AVAsset is actually an AVURLAsset, so if you cast it, you can access it's -url property.

I'm not sure if you can create a new asset out of this, but it does give you the location.