From eb25f78b26cfc24f65071416509303f788249252 Mon Sep 17 00:00:00 2001 From: "Pan, Xinlei (Ryan)" Date: Thu, 10 May 2018 15:42:09 -0400 Subject: [PATCH] add data and response valid for image download --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index de4a78e..bb97f89 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -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 {