Add some callback methods to SDWebImageManager protocol with requested URL appended (fix #67)

This commit is contained in:
Olivier Poitrey 2012-03-10 18:17:54 +01:00
parent 3074f55de2
commit 30b9534294
2 changed files with 19 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#import "SDWebImageManager.h" #import "SDWebImageManager.h"
#import "SDImageCache.h" #import "SDImageCache.h"
#import "SDWebImageDownloader.h" #import "SDWebImageDownloader.h"
#import <objc/message.h>
static SDWebImageManager *instance; static SDWebImageManager *instance;
@ -165,6 +166,10 @@ static SDWebImageManager *instance;
{ {
[delegate performSelector:@selector(webImageManager:didFinishWithImage:) withObject:self withObject:image]; [delegate performSelector:@selector(webImageManager:didFinishWithImage:) withObject:self withObject:image];
} }
if ([delegate respondsToSelector:@selector(webImageManager:didFinishWithImage:forURL:)])
{
objc_msgSend(delegate, @selector(webImageManager:didFinishWithImage:forURL:), self, image, url);
}
[cacheDelegates removeObjectAtIndex:idx]; [cacheDelegates removeObjectAtIndex:idx];
[cacheURLs removeObjectAtIndex:idx]; [cacheURLs removeObjectAtIndex:idx];
@ -229,6 +234,10 @@ static SDWebImageManager *instance;
{ {
[delegate performSelector:@selector(webImageManager:didFinishWithImage:) withObject:self withObject:image]; [delegate performSelector:@selector(webImageManager:didFinishWithImage:) withObject:self withObject:image];
} }
if ([delegate respondsToSelector:@selector(webImageManager:didFinishWithImage:forURL:)])
{
objc_msgSend(delegate, @selector(webImageManager:didFinishWithImage:forURL:), self, image, downloader.url);
}
} }
else else
{ {
@ -236,6 +245,10 @@ static SDWebImageManager *instance;
{ {
[delegate performSelector:@selector(webImageManager:didFailWithError:) withObject:self withObject:nil]; [delegate performSelector:@selector(webImageManager:didFailWithError:) withObject:self withObject:nil];
} }
if ([delegate respondsToSelector:@selector(webImageManager:didFailWithError:forURL:)])
{
objc_msgSend(delegate, @selector(webImageManager:didFailWithError:forURL:), self, nil, downloader.url);
}
} }
[downloaders removeObjectAtIndex:uidx]; [downloaders removeObjectAtIndex:uidx];
@ -283,6 +296,10 @@ static SDWebImageManager *instance;
{ {
[delegate performSelector:@selector(webImageManager:didFailWithError:) withObject:self withObject:error]; [delegate performSelector:@selector(webImageManager:didFailWithError:) withObject:self withObject:error];
} }
if ([delegate respondsToSelector:@selector(webImageManager:didFailWithError:forURL:)])
{
objc_msgSend(delegate, @selector(webImageManager:didFailWithError:forURL:), self, error, downloader.url);
}
[downloaders removeObjectAtIndex:uidx]; [downloaders removeObjectAtIndex:uidx];
[downloadDelegates removeObjectAtIndex:uidx]; [downloadDelegates removeObjectAtIndex:uidx];

View File

@ -14,6 +14,8 @@
@optional @optional
- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image; - (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image;
- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image forURL:(NSURL *)url;
- (void)webImageManager:(SDWebImageManager *)imageManager didFailWithError:(NSError *)error; - (void)webImageManager:(SDWebImageManager *)imageManager didFailWithError:(NSError *)error;
- (void)webImageManager:(SDWebImageManager *)imageManager didFailWithError:(NSError *)error forURL:(NSURL *)url;
@end @end