Browse Source

Allow initialization of AFImageDownloader using custom NSURLSessionConfiguration.

Henddher Pedroza 8 years ago
parent
commit
8db67cdfa9
2 changed files with 19 additions and 1 deletions
  1. 14 0
      UIKit+AFNetworking/AFImageDownloader.h
  2. 5 1
      UIKit+AFNetworking/AFImageDownloader.m

+ 14 - 0
UIKit+AFNetworking/AFImageDownloader.h

@@ -86,6 +86,11 @@ typedef NS_ENUM(NSInteger, AFImageDownloadPrioritization) {
  */
 + (void) setDefaultURLCache:(NSURLCache *)defaultCache;
 
+/**
+ The default `NSURLSessionConfiguration` with common usage parameter values.
+ */
++ (NSURLSessionConfiguration *)defaultURLSessionConfiguration;
+
 /**
  Default initializer
 
@@ -93,6 +98,15 @@ typedef NS_ENUM(NSInteger, AFImageDownloadPrioritization) {
  */
 - (instancetype)init;
 
+/**
+ Initializer with specific `URLSessionConfiguration`
+ 
+ @param configuration The `NSURLSessionConfiguration` to be be used
+ 
+ @return An instance of `AFImageDownloader` initialized with default values and custom `NSURLSessionConfiguration`
+ */
+- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration;
+
 /**
  Initializes the `AFImageDownloader` instance with the given session manager, download prioritization, maximum active download count and image cache.
 

+ 5 - 1
UIKit+AFNetworking/AFImageDownloader.m

@@ -154,7 +154,11 @@ static NSURLCache* _defaultURLCache = nil;
 
 - (instancetype)init {
     NSURLSessionConfiguration *defaultConfiguration = [self.class defaultURLSessionConfiguration];
-    AFHTTPSessionManager *sessionManager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:defaultConfiguration];
+    return [self initWithSessionConfiguration:defaultConfiguration];
+}
+
+- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration {
+    AFHTTPSessionManager *sessionManager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];
     sessionManager.responseSerializer = [AFImageResponseSerializer serializer];
 
     return [self initWithSessionManager:sessionManager