Change the optional method into required, force the custom loader author to provide the error check

This commit is contained in:
DreamPiggy 2019-04-02 17:56:12 +08:00
parent 691873117a
commit 2640301e82
4 changed files with 6 additions and 12 deletions

View File

@ -86,11 +86,9 @@ FOUNDATION_EXPORT UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NS
completed:(nullable SDImageLoaderCompletedBlock)completedBlock;
@optional
/**
Whether the error from image loader should be marked indded un-recoverable or not.
If this return YES, failed URL which does not using `SDWebImageRetryFailed` will be blocked into black list. Else not.
If does not implements this method, assume always return NO.
@param url The URL represent the image. Note this may not be a HTTP URL
@param error The URL's loading error, from previous `requestImageWithURL:options:context:progress:completed:` completedBlock's error.

View File

@ -104,11 +104,7 @@
NSArray<id<SDImageLoader>> *loaders = self.loaders;
for (id<SDImageLoader> loader in loaders.reverseObjectEnumerator) {
if ([loader canRequestImageForURL:url]) {
if ([loader respondsToSelector:@selector(shouldBlockFailedURLWithURL:error:)]) {
return [loader shouldBlockFailedURLWithURL:url error:error];
} else {
return NO;
}
return [loader shouldBlockFailedURLWithURL:url error:error];
}
}
return NO;

View File

@ -374,11 +374,7 @@ static id<SDImageLoader> _defaultImageLoader;
if ([self.delegate respondsToSelector:@selector(imageManager:shouldBlockFailedURL:withError:)]) {
shouldBlockFailedURL = [self.delegate imageManager:self shouldBlockFailedURL:url withError:error];
} else {
if ([self.imageLoader respondsToSelector:@selector(shouldBlockFailedURLWithURL:error:)]) {
shouldBlockFailedURL = [self.imageLoader shouldBlockFailedURLWithURL:url error:error];
} else {
shouldBlockFailedURL = NO;
}
shouldBlockFailedURL = [self.imageLoader shouldBlockFailedURLWithURL:url error:error];
}
return shouldBlockFailedURL;

View File

@ -50,4 +50,8 @@
return task;
}
- (BOOL)shouldBlockFailedURLWithURL:(NSURL *)url error:(NSError *)error {
return NO;
}
@end