fix typo add comments
This commit is contained in:
parent
9d101abbf8
commit
374ae5973a
@ -513,13 +513,14 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
||||
});
|
||||
}
|
||||
|
||||
//download image
|
||||
- (void)downloadImage:(NSURL *)s7URL isGif:(BOOL)isGif fallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler{
|
||||
NSURLCache *sharedCache = [NSURLCache sharedURLCache];
|
||||
NSURLSessionConfiguration *configure = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
configure.URLCache = sharedCache;
|
||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:configure];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:s7URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:ImageTimeOut];
|
||||
|
||||
//use Freebee to download image first, then store image to cache
|
||||
NSCachedURLResponse *cachedResponse = [sharedCache cachedResponseForRequest:request];
|
||||
if (!cachedResponse.data) {
|
||||
cachedResponse = [[MFFreebeeHandler sharedHandler] freebee_dataWithImageURL:s7URL];
|
||||
@ -529,6 +530,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
||||
[sharedCache storeCachedResponse:cachedResponse forRequest:request];
|
||||
}
|
||||
}
|
||||
//call nsurlsession again, if image is cached by Freebee, the second session will grab image data from cache instead of making another server call
|
||||
NSURLSessionDownloadTask *downloadImageTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
NSData *data = [NSData dataWithContentsOfURL:location];
|
||||
NSCachedURLResponse *cachedreponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data];
|
||||
@ -547,6 +549,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
||||
[downloadImageTask resume];
|
||||
}
|
||||
|
||||
//check whehter get image or imageData, if not, return fallbackImage
|
||||
- (void)checkImage:(UIImage *)img imageData:(NSData *)imageData fallbackImage:(NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler{
|
||||
// Set to the fallback image.
|
||||
BOOL isFallBackImage = NO;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user