浏览代码

Ability to set the defaultURLCache

Henddher Pedroza 8 年之前
父节点
当前提交
41897b19c6
共有 2 个文件被更改,包括 16 次插入0 次删除
  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];