CNLiveWebImageDownload.m 1.46 KB
//
//  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