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
|
//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) {
|
NSURLSessionDownloadTask *downloadImageTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||||
NSData *data = [NSData dataWithContentsOfURL:location];
|
NSData *data = [NSData dataWithContentsOfURL:location];
|
||||||
NSCachedURLResponse *cachedReponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data];
|
//check data and response first, since they are nullable
|
||||||
//system stores cache based datatask and check cache based on response,
|
if (data && response) {
|
||||||
//need to manually store cache for response
|
NSCachedURLResponse *cachedReponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data];
|
||||||
[sharedCache storeCachedResponse:cachedReponse forRequest:request];
|
//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) {
|
if (isGif) {
|
||||||
[self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler];
|
[self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user