1818#import " ASBaseDefines.h"
1919#import " ASDisplayNode+Subclasses.h"
2020#import " ASLog.h"
21+ #import " ASPhotosImageRequest.h"
2122
2223#if !AS_IOS8_SDK_OR_LATER
2324#error ASMultiplexImageNode can be used on iOS 7, but must be linked against the iOS 8 SDK.
2627NSString *const ASMultiplexImageNodeErrorDomain = @" ASMultiplexImageNodeErrorDomain" ;
2728
2829static NSString *const kAssetsLibraryURLScheme = @" assets-library" ;
29- static NSString *const kPHAssetURLScheme = @" ph" ;
30- static NSString *const kPHAssetURLPrefix = @" ph://" ;
3130
3231/* *
3332 @abstract Signature for the block to be performed after an image has loaded.
@@ -120,14 +119,14 @@ - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imag
120119- (void )_loadALAssetWithIdentifier : (id )imageIdentifier URL : (NSURL *)assetURL completion : (void (^)(UIImage *image, NSError *error))completionBlock ;
121120
122121/* *
123- @abstract Loads the image corresponding to the given assetURL from the Photos framework.
122+ @abstract Loads the image corresponding to the given image request from the Photos framework.
124123 @param imageIdentifier The identifier for the image to be loaded. May not be nil.
125- @param assetURL The photos framework URL (e.g., "ph://identifier") of the image to load, from PHAsset . May not be nil.
124+ @param request The photos image request to load. May not be nil.
126125 @param completionBlock The block to be performed when the image has been loaded, if possible. May not be nil.
127126 @param image The image that was loaded. May be nil if no image could be downloaded.
128127 @param error An error describing why the load failed, if it failed; nil otherwise.
129128 */
130- - (void )_loadPHAssetWithIdentifier : ( id ) imageIdentifier URL : ( NSURL *) assetURL completion : (void (^)(UIImage *image, NSError *error))completionBlock ;
129+ - (void )_loadPHAssetWithRequest : (ASPhotosImageRequest *) request identifier : ( id ) imageIdentifier completion : (void (^)(UIImage *image, NSError *error))completionBlock ;
131130
132131/* *
133132 @abstract Downloads the image corresponding to the given imageIdentifier from the given URL.
@@ -456,8 +455,8 @@ - (void)_loadNextImage
456455 }];
457456 }
458457 // Likewise, if it's a iOS 8 Photo asset, we need to fetch it accordingly.
459- else if (AS_AT_LEAST_IOS8 && [[nextImageURL scheme ] isEqualToString: kPHAssetURLScheme ] ) {
460- [self _loadPHAssetWithIdentifier: nextImageIdentifier URL: nextImageURL completion: ^(UIImage *image, NSError *error) {
458+ else if (ASPhotosImageRequest *request = nextImageURL. asyncdisplaykit_photosRequest ) {
459+ [self _loadPHAssetWithRequest: request identifier: nextImageIdentifier completion: ^(UIImage *image, NSError *error) {
461460 ASMultiplexImageNodeCLogDebug (@" [%p ] Acquired next image (%@ ) from Photos Framework" , weakSelf, nextImageIdentifier);
462461 finishedLoadingBlock (image, nextImageIdentifier, error);
463462 }];
@@ -511,17 +510,15 @@ - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL com
511510 }];
512511}
513512
514- - (void )_loadPHAssetWithIdentifier : ( id ) imageIdentifier URL : ( NSURL *) assetURL completion : (void (^)(UIImage *image, NSError *error))completionBlock
513+ - (void )_loadPHAssetWithRequest : (ASPhotosImageRequest *) request identifier : ( id ) imageIdentifier completion : (void (^)(UIImage *image, NSError *error))completionBlock
515514{
516515 ASDisplayNodeAssert (AS_AT_LEAST_IOS8, @" PhotosKit is unavailable on iOS 7." );
517516 ASDisplayNodeAssertNotNil (imageIdentifier, @" imageIdentifier is required" );
518- ASDisplayNodeAssertNotNil (assetURL , @" assetURL is required" );
517+ ASDisplayNodeAssertNotNil (request , @" request is required" );
519518 ASDisplayNodeAssertNotNil (completionBlock, @" completionBlock is required" );
520519
521520 // Get the PHAsset itself.
522- ASDisplayNodeAssertTrue ([[assetURL absoluteString ] hasPrefix: kPHAssetURLPrefix ]);
523- NSString *assetIdentifier = [[assetURL absoluteString ] substringFromIndex: [kPHAssetURLPrefix length ]];
524- PHFetchResult *assetFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers: @[assetIdentifier] options: nil ];
521+ PHFetchResult *assetFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers: @[request.assetIdentifier] options: nil ];
525522 if ([assetFetchResult count ] == 0 ) {
526523 // Error.
527524 completionBlock (nil , nil );
@@ -531,15 +528,10 @@ - (void)_loadPHAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL com
531528 // Get the best image we can.
532529 PHAsset *imageAsset = [assetFetchResult firstObject ];
533530
534- PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc ] init ];
535- requestOptions.version = PHImageRequestOptionsVersionCurrent;
536- requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
537- requestOptions.resizeMode = PHImageRequestOptionsResizeModeNone;
538-
539531 [[PHImageManager defaultManager ] requestImageForAsset: imageAsset
540- targetSize: CGSizeMake ( 2048.0 , 2048.0 ) // Ideally we would use PHImageManagerMaximumSize and kill the options, but we get back nil when requesting images of video assets. rdar://18447788
541- contentMode: PHImageContentModeDefault
542- options: requestOptions
532+ targetSize: request.targetSize
533+ contentMode: request.contentMode
534+ options: request.options
543535 resultHandler: ^(UIImage *image, NSDictionary *info) {
544536 completionBlock (image, info[PHImageErrorKey]);
545537 }];
0 commit comments