Displaying ALAsset using QLPreviewController
I want to use QLPreviewController to display ALAssets from Photo Stream QLPreviewController needs NSURL to display item
This works great when it is a file url such as / var / mobile / Applications / 5374 ...... 9E0 / Documents / image33.png
I have ALAsset However using [[default defaultRepresentation] url] gives me the type NSURL
assets-library: //asset/asset.JPG? id = 00000000-0000-0000-0000-000000000075 & ext = JPG
But this doesn't display the QLPreviewController just keeps showing loading
Any ideas? thanks in advance
+3
source to share
1 answer
This may not be the fastest and most efficient way, but it does solve the problem. Please use NSFilemanager instead of NSTemporaryDirectory as in the documentation :-) Make sure to link to ImageIO.framework
#import <ImageIO/ImageIO.h>
....
NSURL *outURLToUseWithQLPreviewController = nil;
ALAsset *myAsset = ... // received somehow
ALAssetRepresentation *represent = myAsset.defaultRepresentation;
CGImageRef representFullScreen = represent.fullScreenImage;
NSString *tempDir = NSTemporaryDirectory();
NSString *imagePath = [tempDir stringByAppendingPathComponent:represent.filename];
NSURL *tempURL = [NSURL fileURLWithPath:imagePath];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)(tempURL), (__bridge CFStringRef)(represent.UTI), 1, NULL);
CGImageDestinationAddImage(destination, representFullScreen, nil);
if ( CGImageDestinationFinalize(destination) ) {
outURLToUseWithQLPreviewController = tempURL;
}
return outURLToUseWithQLPreviewController;
0
source to share