diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m index cd46d1c..6fe372d 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m @@ -40,7 +40,7 @@ NSUInteger const TopAlertDismissTime = 5; } // The default is yes if not sent by server (for legacy to work as is) - NSNumber *closeButton = [responseInfo objectForKey:KeyCloseButton ofType:[NSNumber class]]; + NSNumber *closeButton = [responseInfo optionalNumberForKey:KeyCloseButton]; if (closeButton) { self.useCloseButton = [closeButton boolValue]; } else { @@ -51,7 +51,7 @@ NSUInteger const TopAlertDismissTime = 5; // Server driven dismiss time. if (self.useNewStyle) { - NSNumber *topAlertTime = [responseInfo objectForKey:@"topAlertTime" ofType:[NSNumber class]]; + NSNumber *topAlertTime = [responseInfo optionalNumberForKey:@"topAlertTime"]; if (topAlertTime) { self.topAlertDismissTime = [topAlertTime integerValue]; } diff --git a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h index 6ae8fc6..b6db9fb 100644 --- a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h +++ b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h @@ -23,6 +23,7 @@ - (NSInteger)integer:(nonnull id)key; - (CGFloat)floatForKey:(nonnull id)key; - (double)doubleForKey:(nonnull id)key; +- (nullable NSNumber *)optionalNumberForKey:(nonnull id)key; // Not strict, can accept either string or boolean. - (BOOL)lenientBoolForKey:(nonnull id)key; diff --git a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m index f4e087d..f5dfa7f 100644 --- a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m +++ b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m @@ -29,7 +29,7 @@ } - (BOOL)boolForKey:(nonnull id)key { - return [[self objectForKey:key ofType:[NSNumber class]] boolValue]; + return [[self optionalNumberForKey:key] boolValue]; } - (BOOL)lenientBoolForKey:(nonnull id)key { @@ -42,15 +42,19 @@ } - (CGFloat)floatForKey:(nonnull id)key { - return [[self objectForKey:key ofType:[NSNumber class]] floatValue]; + return [[self optionalNumberForKey:key] floatValue]; } - (double)doubleForKey:(id)key { - return [[self objectForKey:key ofType:[NSNumber class]] doubleValue]; + return [[self optionalNumberForKey:key] doubleValue]; } - (NSInteger)integer:(nonnull id)key { - return [[self objectForKey:key ofType:[NSNumber class]] integerValue]; + return [[self optionalNumberForKey:key] integerValue]; +} + +- (nullable NSNumber *)optionalNumberForKey:(nonnull id)key { + return [self objectForKey:key ofType:[NSNumber class]]; } - (nullable id)objectChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m index 5c56b3a..4dacb59 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m @@ -60,7 +60,7 @@ } - (BOOL)extendsAppSession { - NSNumber *extendSessionFlag = [self.responseInfoMap objectForKey:@"appSessionExtended" ofType:[NSNumber class]]; + NSNumber *extendSessionFlag = [self.responseInfoMap optionalNumberForKey:@"appSessionExtended"]; return !extendSessionFlag || [extendSessionFlag boolValue]; // Default to YES if the key does not exist. } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index b72132a..5030046 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -67,7 +67,7 @@ if (self = [self initWithPageType:[actionMap stringForKey:KeyPageType] additionalModules:[actionMap array:KeyModuleList] extraParameters:[actionMap dict:KeyExtraParameters]]) { self.contextRoot = [actionMap string:KeyContextRoot]; self.actionMap = actionMap; - self.customTimeoutTime = [actionMap objectForKey:@"customTimeoutTime" ofType:[NSNumber class]]; + self.customTimeoutTime = [actionMap optionalNumberForKey:@"customTimeoutTime"]; self.openSupportPanel = [actionMap boolForKey:KeyOpenSupport]; // Right now server is sending default.... can't uncomment this until they remove default diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 68cc85d..cc6a666 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -218,7 +218,10 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } // Adds json to cache with page type key. - [weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType]; + NSNumber *shouldCache = [jsonDictionary optionalNumberForKey:@"cache"]; + if (!shouldCache || shouldCache.boolValue) { + [weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType]; + } } } if (completionBlock) { @@ -250,9 +253,12 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; // Create the cache if necessary. weakSelf.moduleCache = [NSMutableDictionary dictionary]; } - + // Adds json to cache with page type key. - [weakSelf.moduleCache setObject:obj forKey:key]; + NSNumber *shouldCache = [jsonDictionary optionalNumberForKey:@"cache"]; + if (!shouldCache || shouldCache.boolValue) { + [weakSelf.moduleCache setObject:obj forKey:key]; + } } }]; }