From 4274158949e67ce15d9c92abba1460359c8d3997 Mon Sep 17 00:00:00 2001 From: lizhuoli Date: Mon, 18 Oct 2021 21:30:34 +0800 Subject: [PATCH 1/2] Fix the support for `SDImageLoadersManager` for canRequest API check, should be compatible with both old and new API --- SDWebImage/Core/SDImageLoadersManager.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SDWebImage/Core/SDImageLoadersManager.m b/SDWebImage/Core/SDImageLoadersManager.m index eae906f2..ac86c29d 100644 --- a/SDWebImage/Core/SDImageLoadersManager.m +++ b/SDWebImage/Core/SDImageLoadersManager.m @@ -78,10 +78,20 @@ #pragma mark - SDImageLoader - (BOOL)canRequestImageForURL:(nullable NSURL *)url { + return [self canRequestImageForURL:url options:0 context:nil]; +} + +- (BOOL)canRequestImageForURL:(NSURL *)url options:(SDWebImageOptions)options context:(SDWebImageContext *)context { NSArray> *loaders = self.loaders; for (id loader in loaders.reverseObjectEnumerator) { - if ([loader canRequestImageForURL:url]) { - return YES; + if ([loader respondsToSelector:@selector(canRequestImageForURL:options:context:)]) { + if ([loader canRequestImageForURL:url options:options context:context]) { + return YES; + } + } else { + if ([loader canRequestImageForURL:url]) { + return YES; + } } } return NO; From c0fbe7e3efa7f88389f746a36b39d525ae3652f8 Mon Sep 17 00:00:00 2001 From: lizhuoli Date: Mon, 18 Oct 2021 21:44:01 +0800 Subject: [PATCH 2/2] Update test case --- Tests/Tests/SDWebImageDownloaderTests.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Tests/SDWebImageDownloaderTests.m b/Tests/Tests/SDWebImageDownloaderTests.m index a2506ce2..addae28e 100644 --- a/Tests/Tests/SDWebImageDownloaderTests.m +++ b/Tests/Tests/SDWebImageDownloaderTests.m @@ -774,6 +774,7 @@ SDWebImageTestLoader *loader = [[SDWebImageTestLoader alloc] init]; NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL]; expect([loader canRequestImageForURL:imageURL]).beTruthy(); + expect([loader canRequestImageForURL:imageURL options:0 context:nil]).beTruthy(); NSError *imageError = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:nil]; expect([loader shouldBlockFailedURLWithURL:imageURL error:imageError]).equal(NO); @@ -797,6 +798,7 @@ manager.loaders = @[SDWebImageDownloader.sharedDownloader, loader]; NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL]; expect([manager canRequestImageForURL:imageURL]).beTruthy(); + expect([manager canRequestImageForURL:imageURL options:0 context:nil]).beTruthy(); NSError *imageError = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:nil]; expect([manager shouldBlockFailedURLWithURL:imageURL error:imageError]).equal(NO);