Browse Source

Ability to set the defaultURLCache

Henddher Pedroza 8 years ago
parent
commit
41897b19c6
2 changed files with 16 additions and 0 deletions
  1. 5 0
      UIKit+AFNetworking/AFImageDownloader.h
  2. 11 0
      UIKit+AFNetworking/AFImageDownloader.m

+ 5 - 0
UIKit+AFNetworking/AFImageDownloader.h

@@ -81,6 +81,11 @@ typedef NS_ENUM(NSInteger, AFImageDownloadPrioritization) {
  */
 + (NSURLCache *)defaultURLCache;
 
+/**
+ Sets the default `NSURLCache`
+ */
++ (void) setDefaultURLCache:(NSURLCache *)defaultCache;
+
 /**
  Default initializer
 

+ 11 - 0
UIKit+AFNetworking/AFImageDownloader.m

@@ -106,10 +106,16 @@
 
 @end
 
+static NSURLCache* _defaultURLCache = nil;
 
 @implementation AFImageDownloader
 
 + (NSURLCache *)defaultURLCache {
+    
+    if (_defaultURLCache) {
+        return _defaultURLCache;
+    }
+    
     // It's been discovered that a crash will occur on certain versions
     // of iOS if you customize the cache.
     //
@@ -125,6 +131,11 @@
                                              diskPath:@"com.alamofire.imagedownloader"];
 }
 
++ (void)setDefaultURLCache:(NSURLCache *)defaultCache {
+    
+    _defaultURLCache = defaultCache;
+}
+
 + (NSURLSessionConfiguration *)defaultURLSessionConfiguration {
     NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];