add data and response valid for image download
This commit is contained in:
parent
38c7687acd
commit
eb25f78b26
@ -533,10 +533,13 @@ 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];
|
||||
//system stores cache based datatask and check cache based on response,
|
||||
//need to manually store cache for response
|
||||
[sharedCache storeCachedResponse:cachedReponse forRequest:request];
|
||||
//check data and response first, since they are nullable
|
||||
if (data && response) {
|
||||
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];
|
||||
}
|
||||
if (isGif) {
|
||||
[self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler];
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user