Jelajahi Sumber

Ability to set the defaultURLCache

Henddher Pedroza 8 tahun lalu
induk
melakukan
41897b19c6

+ 5 - 0
UIKit+AFNetworking/AFImageDownloader.h

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

+ 11 - 0
UIKit+AFNetworking/AFImageDownloader.m

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