diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm index b9f6514fb7..e24e380868 100755 --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -457,15 +457,27 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0}; } else { // First try to load the path directly, for efficiency assuming a developer who // doesn't want caching is trying to be as minimal as possible. - self.image = [UIImage imageWithContentsOfFile:_URL.path]; - if (!self.image) { + NSData *data = [NSData dataWithContentsOfURL:_URL]; + if (data == nil) { // If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the // extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage. NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil]; - if (filename) { - self.image = [UIImage imageWithContentsOfFile:filename]; + if (filename != nil) { + data = [NSData dataWithContentsOfFile:filename]; } } + + // If the file may be an animated gif and then created an animated image. + id animatedImage = nil; + if (_downloaderImplementsAnimatedImage && data != nil && [_URL.pathExtension isEqualToString:@"gif"]) { + animatedImage = [_downloader animatedImageWithData:data]; + } + + if (animatedImage != nil) { + self.animatedImage = animatedImage; + } else { + self.image = [UIImage imageWithData:data]; + } } _imageLoaded = YES;