From 9c537ead5dd47f5b7cf89d05f893be5bb64c0c30 Mon Sep 17 00:00:00 2001 From: ernestmama <43187788+ernestmama@users.noreply.github.com> Date: Fri, 19 Jul 2019 11:45:37 -0700 Subject: [PATCH] Add a new networking image delegate method when a network image node failed to load from cache (#1590) --- Source/ASNetworkImageNode.h | 9 +++++++++ Source/ASNetworkImageNode.mm | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/Source/ASNetworkImageNode.h b/Source/ASNetworkImageNode.h index 33bddb19d..7f505c420 100644 --- a/Source/ASNetworkImageNode.h +++ b/Source/ASNetworkImageNode.h @@ -172,6 +172,15 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)imageNodeDidLoadImageFromCache:(ASNetworkImageNode *)imageNode; +/** + * Notification that the image node failed to load image from cache + * + * @param imageNode The sender. + * + * @discussion Called on the main thread. + */ +- (void)imageNodeDidFailToLoadImageFromCache:(ASNetworkImageNode *)imageNode; + /** * Notification that the image node will load image from network * diff --git a/Source/ASNetworkImageNode.mm b/Source/ASNetworkImageNode.mm index 70be47f58..044184eb0 100644 --- a/Source/ASNetworkImageNode.mm +++ b/Source/ASNetworkImageNode.mm @@ -57,6 +57,7 @@ @interface ASNetworkImageNode () unsigned int delegateDidLoadImage:1; unsigned int delegateDidLoadImageFromCache:1; unsigned int delegateDidLoadImageWithInfo:1; + unsigned int delegateDidFailToLoadImageFromCache:1; unsigned int downloaderImplementsSetProgress:1; unsigned int downloaderImplementsSetPriority:1; @@ -298,6 +299,7 @@ - (void)setDelegate:(id)delegate _networkImageNodeFlags.delegateDidLoadImage = [delegate respondsToSelector:@selector(imageNode:didLoadImage:)]; _networkImageNodeFlags.delegateDidLoadImageFromCache = [delegate respondsToSelector:@selector(imageNodeDidLoadImageFromCache:)]; _networkImageNodeFlags.delegateDidLoadImageWithInfo = [delegate respondsToSelector:@selector(imageNode:didLoadImage:info:)]; + _networkImageNodeFlags.delegateDidFailToLoadImageFromCache = [delegate respondsToSelector:@selector(imageNodeDidFailToLoadImageFromCache:)]; } - (id)delegate @@ -665,6 +667,7 @@ - (void)_lazilyLoadImageIfNecessary BOOL delegateWillLoadImageFromCache = _networkImageNodeFlags.delegateWillLoadImageFromCache; BOOL delegateWillLoadImageFromNetwork = _networkImageNodeFlags.delegateWillLoadImageFromNetwork; BOOL delegateDidLoadImageFromCache = _networkImageNodeFlags.delegateDidLoadImageFromCache; + BOOL delegateDidFailToLoadImageFromCache = _networkImageNodeFlags.delegateDidFailToLoadImageFromCache; BOOL isImageLoaded = _networkImageNodeFlags.imageLoaded; __block NSURL *URL = _URL; id currentDownloadIdentifier = _downloadIdentifier; @@ -824,6 +827,9 @@ - (void)_lazilyLoadImageIfNecessary } if ([imageContainer asdk_image] == nil && [imageContainer asdk_animatedImageData] == nil && self->_downloader != nil) { + if (delegateDidFailToLoadImageFromCache) { + [delegate imageNodeDidFailToLoadImageFromCache:self]; + } if (delegateWillLoadImageFromNetwork) { [delegate imageNodeWillLoadImageFromNetwork:self]; }