-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathWebImageView.m
37 lines (31 loc) · 1.07 KB
/
WebImageView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "WebImageView.h"
@implementation WebImageView{
BOOL isCallback;
}
- (void)setSource:(WebImageSource *)source {
_source = source;
isCallback= NO;
SDWebImageManager* manager =[[SDWebImageManager alloc] init];
[manager cachedImageExistsForURL:source.uri completion:^(BOOL inCache) {
if(!inCache || isCallback) return ;
if(_onWebImageSuccess){
_onWebImageSuccess(@{ @"uri":self->_source.uri.absoluteString, @"type" : @"cache"});
}
isCallback = YES;
}];
[self sd_setImageWithURL:source.uri completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (error) {
if (_onWebImageError) {
_onWebImageError(@{@"error":error.description, @"uri":imageURL.absoluteString});
}
return;
}
else{
if(_onWebImageSuccess && !self->isCallback){
self->isCallback = YES;
_onWebImageSuccess(@{ @"uri":imageURL.absoluteString});
}
}
}];
}
@end