Merge pull request #1654 from Wondermall/session-configuration
Allow to specify NSURLSessionConfiguration for SDWebImageDownloader
This commit is contained in:
commit
9012d268a9
|
@ -149,6 +149,13 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB
|
|||
*/
|
||||
@property (nonatomic, copy, nullable) SDWebImageDownloaderHeadersFilterBlock headersFilter;
|
||||
|
||||
/**
|
||||
* Creates an instance of a downloader with specified session configuration.
|
||||
* *Note*: `timeoutIntervalForRequest` is going to be overwritten.
|
||||
* @return new instance of downloader class
|
||||
*/
|
||||
- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
/**
|
||||
* Set a value for a HTTP header to be appended to each download HTTP request.
|
||||
*
|
||||
|
|
|
@ -64,6 +64,10 @@
|
|||
}
|
||||
|
||||
- (nonnull instancetype)init {
|
||||
return [self initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
|
||||
}
|
||||
|
||||
- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration {
|
||||
if ((self = [super init])) {
|
||||
_operationClass = [SDWebImageDownloaderOperation class];
|
||||
_shouldDecompressImages = YES;
|
||||
|
@ -80,15 +84,14 @@
|
|||
_barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
|
||||
_downloadTimeout = 15.0;
|
||||
|
||||
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
sessionConfig.timeoutIntervalForRequest = _downloadTimeout;
|
||||
sessionConfiguration.timeoutIntervalForRequest = _downloadTimeout;
|
||||
|
||||
/**
|
||||
* Create the session for this task
|
||||
* We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
|
||||
* method calls and completion handler calls.
|
||||
*/
|
||||
self.session = [NSURLSession sessionWithConfiguration:sessionConfig
|
||||
self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration
|
||||
delegate:self
|
||||
delegateQueue:nil];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue