From b75b72c6600f56349d73f06702c709757b1690c5 Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sun, 27 Dec 2015 16:38:34 -0800 Subject: [PATCH] Improve handling of file URLs for ASNetworkImageNode. Details discussed in https://github.com/facebook/AsyncDisplayKit/pull/1003. This PR supercedes that one. --- AsyncDisplayKit/ASNetworkImageNode.mm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) mode change 100644 => 100755 AsyncDisplayKit/ASNetworkImageNode.mm diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm old mode 100644 new mode 100755 index c1437ef814..cbba35af9c --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -188,14 +188,23 @@ ASDN::MutexLocker l(_lock); dispatch_async(dispatch_get_main_queue(), ^{ - _imageLoaded = YES; - if (self.shouldCacheImage) { - self.image = [UIImage imageNamed:_URL.path]; + self.image = [UIImage imageNamed:_URL.path.lastPathComponent]; } 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) { + // 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]; + } + } } - + + _imageLoaded = YES; [_delegate imageNode:self didLoadImage:self.image]; }); }