check fall back image for s7 image
This commit is contained in:
parent
2ca6c854d8
commit
6700d97b81
@ -519,7 +519,6 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
|||||||
|
|
||||||
- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler {
|
- (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler {
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
BOOL isFallBackImage = NO;
|
|
||||||
UIImage *img = nil;
|
UIImage *img = nil;
|
||||||
if (pathOrName.length > 0) {
|
if (pathOrName.length > 0) {
|
||||||
|
|
||||||
@ -539,15 +538,22 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
|||||||
if (!cachedResponse.data) {
|
if (!cachedResponse.data) {
|
||||||
cachedResponse = [[MFFreebeeHandler sharedHandler] freebee_dataWithImageURL:s7URL];
|
cachedResponse = [[MFFreebeeHandler sharedHandler] freebee_dataWithImageURL:s7URL];
|
||||||
if (cachedResponse) {
|
if (cachedResponse) {
|
||||||
|
//system stores cache based datatask and check cache based on response,
|
||||||
|
//need to manually store cache for response
|
||||||
[sharedCache storeCachedResponse:cachedResponse forRequest:request];
|
[sharedCache storeCachedResponse:cachedResponse forRequest:request];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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];
|
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];
|
||||||
UIImage *image = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale];
|
UIImage *image = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale];
|
||||||
completionHandler(image, nil, isFallBackImage);
|
|
||||||
|
//check fallback image
|
||||||
|
[self checkImage:image fallbackImage:fallbackImageName completionHandler:completionHandler];
|
||||||
|
|
||||||
}];
|
}];
|
||||||
[downloadImageTask resume];
|
[downloadImageTask resume];
|
||||||
return;
|
return;
|
||||||
@ -566,24 +572,29 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[self checkImage:img fallbackImage:fallbackImageName completionHandler:completionHandler];
|
||||||
|
|
||||||
// Set to the fallback image.
|
});
|
||||||
if (!img && fallbackImageName) {
|
}
|
||||||
isFallBackImage = YES;
|
|
||||||
// Grab fallback from cache
|
- (void)checkImage:(UIImage *)img fallbackImage:(NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler{
|
||||||
img = [self getCachedImageWithName:fallbackImageName];
|
// Set to the fallback image.
|
||||||
if (!img) {
|
BOOL isFallBackImage = NO;
|
||||||
|
if (!img && fallbackImageName) {
|
||||||
|
isFallBackImage = YES;
|
||||||
|
// Grab fallback from cache
|
||||||
|
img = [self getCachedImageWithName:fallbackImageName];
|
||||||
|
if (!img) {
|
||||||
|
|
||||||
|
img = [UIImage imageNamed:fallbackImageName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil];
|
||||||
|
if (img) {
|
||||||
|
|
||||||
img = [UIImage imageNamed:fallbackImageName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil];
|
// Cache the fallback image if not already cached.
|
||||||
if (img) {
|
[self addImageToCache:img withName:fallbackImageName];
|
||||||
|
|
||||||
// Cache the fallback image if not already cached.
|
|
||||||
[self addImageToCache:img withName:fallbackImageName];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
completionHandler(img, nil, isFallBackImage);
|
}
|
||||||
});
|
completionHandler(img, nil, isFallBackImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable UIImage *)getCachedImageWithName:(nonnull NSString *)imageName {
|
- (nullable UIImage *)getCachedImageWithName:(nonnull NSString *)imageName {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user