This commit is contained in:
Pan, Xinlei (Ryan) 2018-05-10 11:39:09 -04:00
parent f45daa0320
commit ebb5303711

View File

@ -533,10 +533,10 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
//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];
NSCachedURLResponse *cachedReponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data];
//system stores cache based datatask and check cache based on response,
//need to manually store cache for response
[sharedCache storeCachedResponse:cachedreponse forRequest:request];
[sharedCache storeCachedResponse:cachedReponse forRequest:request];
if (isGif) {
[self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler];
} else {
@ -544,12 +544,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
//check fallback image
[self checkImage:image imageData:nil fallbackImage:fallbackImageName completionHandler:completionHandler];
}
}];
[downloadImageTask resume];
}
//check whehter get image or imageData, if not, return fallbackImage
//check whether 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;