Merge pull request #487 from Gabro/patch-1
Enforced presence of a completedBlock in downloadWithURL:options:progress:completed
This commit is contained in:
commit
2bded38216
|
@ -142,7 +142,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
* @param progressBlock A block called while image is downloading
|
||||
* @param completedBlock A block called when operation has been completed.
|
||||
*
|
||||
* This block as no return value and takes the requested UIImage as first parameter.
|
||||
* This parameter is required.
|
||||
*
|
||||
* This block has no return value and takes the requested UIImage as first parameter.
|
||||
* In case of error the image parameter is nil and the second parameter may contain an NSError.
|
||||
*
|
||||
* The third parameter is an `SDImageCacheType` enum indicating if the image was retrived from the local cache
|
||||
|
|
|
@ -68,6 +68,9 @@
|
|||
|
||||
- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock
|
||||
{
|
||||
// Invoking this method without a completedBlock is pointless
|
||||
NSParameterAssert(completedBlock);
|
||||
|
||||
// Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't
|
||||
// throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString.
|
||||
if ([url isKindOfClass:NSString.class])
|
||||
|
@ -90,16 +93,13 @@
|
|||
isFailedUrl = [self.failedURLs containsObject:url];
|
||||
}
|
||||
|
||||
if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && isFailedUrl))
|
||||
if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl))
|
||||
{
|
||||
if (completedBlock)
|
||||
dispatch_main_sync_safe(^
|
||||
{
|
||||
dispatch_main_sync_safe(^
|
||||
{
|
||||
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, YES);
|
||||
});
|
||||
}
|
||||
});
|
||||
return operation;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue