Add a way to check if data is in a format supported by a class implementing ASAnimatedImageProtocol

This commit is contained in:
Eric Jensen
2016-06-09 10:36:18 -07:00
parent 1fb3ffc6f8
commit 91e6df0af9
3 changed files with 19 additions and 1 deletions

View File

@@ -469,9 +469,13 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
// If the file may be an animated gif and then created an animated image.
id<ASAnimatedImageProtocol> animatedImage = nil;
if (_downloaderImplementsAnimatedImage && [_URL.pathExtension isEqualToString:@"gif"]) {
if (_downloaderImplementsAnimatedImage) {
NSData *data = [NSData dataWithContentsOfURL:_URL];
animatedImage = [_downloader animatedImageWithData:data];
if ([animatedImage respondsToSelector:@selector(isDataSupported:)] && [animatedImage isDataSupported:data] == NO) {
animatedImage = nil;
}
}
if (animatedImage != nil) {

View File

@@ -142,12 +142,21 @@ withDownloadIdentifier:(id)downloadIdentifier;
@protocol ASAnimatedImageProtocol <NSObject>
@optional
/**
@abstract Should be called when the objects cover image is ready.
@param coverImageReadyCallback a block which receives the cover image.
*/
@property (nonatomic, strong, readwrite) void (^coverImageReadyCallback)(UIImage *coverImage);
/**
@abstract Returns whether the supplied data contains a supported animated image format.
@param data the data to check if contains a supported animated image.
*/
- (BOOL)isDataSupported:(NSData *)data;
@required
/**

View File

@@ -56,6 +56,11 @@
return self.fileReady;
}
- (BOOL)isDataSupported:(NSData *)data
{
return [data pin_isGIF];
}
@end
#endif