Improve handling of file URLs for ASNetworkImageNode.

Details discussed in https://github.com/facebook/AsyncDisplayKit/pull/1003.  This PR supercedes that one.
This commit is contained in:
Scott Goodson 2015-12-27 16:38:34 -08:00
parent e56315dba9
commit b75b72c660

17
AsyncDisplayKit/ASNetworkImageNode.mm Normal file → Executable file
View File

@ -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];
});
}