Merge pull request #3293 from dreampiggy/bugfix_image_loaders_can_request
Fix the support for `SDImageLoadersManager` for canRequest API check, should be compatible with both old and new API
This commit is contained in:
commit
602af15947
|
@ -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<id<SDImageLoader>> *loaders = self.loaders;
|
||||
for (id<SDImageLoader> 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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue