The API has slightly changed the rules, and you no longer have direct access to the file system in the iPhoto library. Instead, you get the URL of the resource library.
assets-library://asset/asset.JPG?id=1000000003&ext=JPG
You use the ALAssetLibrary object to access the ALAsset object through a URL.
so from the docs for ALAssetLibrary write this in the header (or your source)
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset); typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
which is not strictly necessary, but keeps things pretty. and then at your source.
-(void)findLargeImage { NSString *mediaurl = [self.node valueForKey:kVMMediaURL]; // ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation *rep = [myasset defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; if (iref) { largeimage = [UIImage imageWithCGImage:iref]; [largeimage retain]; } }; // ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) { NSLog(@"booya, cant get image - %@",[myerror localizedDescription]); }; if(mediaurl && [mediaurl length] && ![[mediaurl pathExtension] isEqualToString:AUDIO_EXTENSION]) { [largeimage release]; NSURL *asseturl = [NSURL URLWithString:mediaurl]; ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease]; [assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock]; } }
A few things to note that this uses blocks that were new to me before I started porting iOS4, but you can take a look
https://www.mikeash.com/pyblog/friday-qa-2008-12-26.html
and
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html
They tilt their heads slightly, but if you think of them as notification selectors or callbacks, that helps.
Also
- when
findLargeImage returns resultblock will not be launched as its callback. So largeImage will not be valid yet. largeImage must be an instance variable not bound to a Method.
I use this construct to do this using this method, but you may find something more suitable for your use.
[node.view findLargeImage]; UIImage *thumb = node.view.largeImage; if (thumb) { blah blah }
What I learned while trying to get this to work anyway.
IOS 5 update
When the resulting block is triggered with iOS5 and possibly single-core devices, I cannot rely on the image available immediately after calling findLargeImage . So I changed it to call a delegate.
@protocol HiresImageDelegate <NSObject> @optional -(void)hiresImageAvailable:(UIImage *)aimage; @end
and comme cรก
// ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation *rep = [myasset defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; if (iref) { UIImage *largeimage = [UIImage imageWithCGImage:iref]; [delegate hiresImageAvailable:large]; } };