diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 223ab5f..ad6b87b 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -122,8 +122,9 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO // In the future, may need to use align for the shop flow. // localFallbackImageName: should be the name of a local file to use in case of failure to download. - (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; -- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; -- (void)getGif:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName allowServerQueryParameters:(BOOL)allowServerParams completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; +- (void)getGif:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName allowServerQueryParameters:(BOOL)allowServerParams completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; // Gets a cropped version of the requested image. Similar to the method above, but you can specify the final rect - (void)getCroppedImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flipImage localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index acb69b0..f55d0c2 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -392,7 +392,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; return imageName.length >=4 && [[imageName substringToIndex:4] isEqualToString:@"http"]; } -- (NSURL *)handleS7Path:(NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flipImage { +- (NSURL *)handleS7Path:(NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flipImage allowServerQueryParameters:(BOOL)allowServerParams { // For scene 7 NSURLComponents *components = [[NSURLComponents alloc] initWithString:pathOrName]; @@ -401,8 +401,13 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; // First, remove any hash tag sent by the server because it invalidates our parameters. components.fragment = nil; + if (!allowServerParams) { + components.query = nil; + components.queryItems = nil; + } + // Set up the new query parameters. - NSMutableArray *newQueries = [[NSMutableArray alloc] init]; + NSMutableArray *newQueries = [[NSMutableArray alloc] initWithArray:components.queryItems]; // By default use png format. NSString *s7Format = format; @@ -429,10 +434,6 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; [newQueries addObject:[[NSURLQueryItem alloc] initWithName:@"flip" value:@"lr"]]; } - // Temporary. We will stop stripping parameters after server stops sending bad values... - components.query = nil; - components.queryItems = nil; - if (newQueries.count > 0) { if (components.queryItems.count > 0) { @@ -459,21 +460,25 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } - (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { - [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil localFallbackImageName:fallbackImageName completionHandler:completionHandler]; + [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil finalRect:CGRectNull flipImage:NO localFallbackImageName:fallbackImageName allowServerQueryParameters:NO completionHandler:completionHandler]; } - (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { - [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO localFallbackImageName:fallbackImageName completionHandler:completionHandler]; + [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO localFallbackImageName:fallbackImageName allowServerQueryParameters:NO completionHandler:completionHandler]; } -- (void)getGif:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { +- (void)getImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName allowServerQueryParameters:(BOOL)allowServerParams completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { + [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO localFallbackImageName:fallbackImageName allowServerQueryParameters:allowServerParams completionHandler:completionHandler]; +} + +- (void)getGif:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format localFallbackImageName:(nullable NSString *)fallbackImageName allowServerQueryParameters:(BOOL)allowServerParams completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData *imageData = nil; if (pathOrName.length > 0) { if ([MVMCoreCache isHostedImage:pathOrName]) { // Gets the full path - NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO]; + NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO allowServerQueryParameters:allowServerParams]; if (s7URL) { [self downloadImage:s7URL isGif:YES fallbackImageName:fallbackImageName completionHandler:completionHandler]; return; @@ -495,17 +500,22 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; - (void)getCroppedImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { - [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil finalRect:finalRect flipImage:flip localFallbackImageName:fallbackImageName completionHandler:completionHandler]; + [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil finalRect:finalRect flipImage:flip localFallbackImageName:fallbackImageName allowServerQueryParameters:NO completionHandler:completionHandler]; } -- (void)getImage:(nullable 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)getCroppedImage:(nullable NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName allowServerQueryParameters:(BOOL)allowServerParams completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { + + [self getImage:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:nil finalRect:finalRect flipImage:flip localFallbackImageName:fallbackImageName allowServerQueryParameters:allowServerParams completionHandler:completionHandler]; +} + +- (void)getImage:(nullable 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 allowServerQueryParameters:(BOOL)serverQueryParams completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIImage *image = nil; if (pathOrName.length > 0) { // try the url if it's a url. if ([MVMCoreCache isHostedImage:pathOrName]) { // Gets the full path - NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:finalRect flipImage:flip]; + NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:finalRect flipImage:flip allowServerQueryParameters:serverQueryParams]; if (s7URL) { [self downloadImage:s7URL isGif:NO fallbackImageName:fallbackImageName completionHandler:completionHandler]; return;