JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "UIImageView+Surface.h"
#import <SDWebImage/SDWebImage.h>
 
@implementation UIImageView (Surface)
 
- (void)lc_setThumbImageWithURL:(NSString *)url placeholderImage:(UIImage *)placeholder DeviceId:(NSString *)deviceId ChannelId:(NSString *)chanelId {
//    if (url&&![url isEqualToString:@""]) {
//        [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeholder];
//        return;
//    }
    [self setImage:placeholder];
    SDImageCache* cache = [SDImageCache sharedImageCache];
    NSString* key_temp = [NSString stringWithFormat:@"thumbimg_%@_%@",deviceId,chanelId];
    if ([cache diskImageDataExistsWithKey:key_temp]) {
         [self setImage:[cache imageFromDiskCacheForKey:key_temp]];
    }
}
 
- (void)lc_storeImage:(UIImage *)image ForDeviceId:(NSString *)deviceId ChannelId:(NSString *)chanelId {
    if (!image || !deviceId || [deviceId isEqualToString:@""] || !chanelId || [chanelId isEqualToString:@""]) {
        NSLog(@"参数错误");
        return;
    }
    SDImageCache* cache = [SDImageCache sharedImageCache];
    NSString* key_temp = [NSString stringWithFormat:@"thumbimg_%@_%@",deviceId,chanelId];
    [cache storeImage:image forKey:key_temp toDisk:YES completion:^{
        NSLog(@"储存本地封面图成功");
    }];
}
 
- (BOOL)lc_deskCacheIsExistThumbImageForDeviceId:(NSString *)deviceId ChannelId:(NSString *)chanelId {
    SDImageCache* cache = [SDImageCache sharedImageCache];
    NSString* key_temp = [NSString stringWithFormat:@"thumbimg_%@_%@",deviceId,chanelId];
    return [cache diskImageDataExistsWithKey:key_temp];
}
 
- (void)lc_deleteThumbImageWithDeviceId:(NSString *)deviceId ChannelId:(NSString *)chanelId {
    if ([self lc_deskCacheIsExistThumbImageForDeviceId:deviceId ChannelId:chanelId]) {
        SDImageCache* cache = [SDImageCache sharedImageCache];
        NSString* key_temp = [NSString stringWithFormat:@"thumbimg_%@_%@",deviceId,chanelId];
        [cache removeImageForKey:key_temp withCompletion:^{
            NSLog(@"本地图片缓存删除成功");
        }];
    }
}
 
@end