CNLiveWebImageDownload.m
1.46 KB
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
52
53
54
//
// CNLiveWebImageDownload.m
// WSWebImageDemo
//
// Created by 王帅 on 16/7/14.
// Copyright © 2016年 王帅. All rights reserved.
//
#import "CNLiveWebImageDownload.h"
#import "CNLiveWebImageDownloadOperation.h"
@interface CNLiveWebImageDownload ()
@property (nonatomic, strong) NSOperationQueue *downloadQueue;
@end
@implementation CNLiveWebImageDownload
+ (CNLiveWebImageDownload *)sharedDownload
{
static dispatch_once_t once;
static id instance;
dispatch_once(&once, ^{
instance = [self new];
});
return instance;
}
- (instancetype)init
{
if ((self = [super init])) {
_downloadQueue = [NSOperationQueue new];
_downloadQueue.maxConcurrentOperationCount = 6;
}
return self;
}
- (void)dealloc
{
[self.downloadQueue cancelAllOperations];
}
- (id<CNLiveWebImageOperation>)downloadWebImageWithURL:(NSURL *)url options:(CNLiveWebImageDownloadOptions)options progress:(CNLiveDownloadProgressBlock)progress completed:(CNLiveDownloadCompletedBlock)completed
{
CNLiveWebImageDownloadOperation *operation;
operation = [[CNLiveWebImageDownloadOperation alloc] initWithURL:url
options:options
progress:progress
completed:completed];
[self.downloadQueue addOperation:operation];
return (id <CNLiveWebImageOperation>)operation;
}
@end