From 0456ffcf57e846f0b7c0c6f4bc7cebc1c89c4936 Mon Sep 17 00:00:00 2001 From: Nikolay Demyankov Date: Thu, 1 Oct 2015 12:50:35 +0200 Subject: [PATCH] Added some additional nil handling. Relates to https://github.com/nordnet/cordova-hot-code-push/issues/13 --- src/ios/Config/HCPApplicationConfig.m | 10 +++++++++- src/ios/Config/HCPContentConfig.m | 25 ++++++++++++++++++++----- src/ios/JS/CDVPluginResult+HCPEvents.m | 9 ++++++++- src/ios/Utils/NSBundle+HCPExtension.m | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/ios/Config/HCPApplicationConfig.m b/src/ios/Config/HCPApplicationConfig.m index 9f89f9e3..5749fdfe 100644 --- a/src/ios/Config/HCPApplicationConfig.m +++ b/src/ios/Config/HCPApplicationConfig.m @@ -46,7 +46,15 @@ - (NSString *)storeUrl { #pragma mark HCPJsonConvertable implementation - (id)toJson { - NSMutableDictionary *jsonObject = [[NSMutableDictionary alloc] initWithDictionary:[self.contentConfig toJson]]; + NSMutableDictionary *jsonObject; + NSDictionary *contentConfigJsonObject = [self.contentConfig toJson]; + + if (contentConfigJsonObject) { + jsonObject = [[NSMutableDictionary alloc] initWithDictionary:contentConfigJsonObject]; + } else { + jsonObject = [[NSMutableDictionary alloc] init]; + } + if (self.storeIdentifier) { jsonObject[STORE_PACKAGE_IDENTIFIER_JSON_KEY] = self.storeIdentifier; } diff --git a/src/ios/Config/HCPContentConfig.m b/src/ios/Config/HCPContentConfig.m index fad4b445..c04cc016 100644 --- a/src/ios/Config/HCPContentConfig.m +++ b/src/ios/Config/HCPContentConfig.m @@ -86,11 +86,26 @@ - (HCPUpdateTime)updateTimeStringToEnum:(NSString *)updateTime { #pragma mark HCPJsonConvertable implementation -- (id)toJson { - return @{RELEASE_VERSION_JSON_KEY: _releaseVersion, - MINIMUM_NATIVE_VERSION_JSON_KEY: [NSNumber numberWithInteger:_minimumNativeVersion], - UPDATE_TIME_JSON_KEY: [self updateTimeEnumToString:_updateTime], - CONTENT_URL_JSON_KEY: _contentURL.absoluteString}; +- (id)toJson { + NSMutableDictionary *jsonObject = [[NSMutableDictionary alloc] init]; + if (_releaseVersion) { + jsonObject[RELEASE_VERSION_JSON_KEY] = _releaseVersion; + } + + if (_minimumNativeVersion > 0) { + jsonObject[MINIMUM_NATIVE_VERSION_JSON_KEY] = [NSNumber numberWithInteger:_minimumNativeVersion]; + } + + NSString *updateTimeStr = [self updateTimeEnumToString:_updateTime]; + if (updateTimeStr) { + jsonObject[UPDATE_TIME_JSON_KEY] = updateTimeStr; + } + + if (_contentURL) { + jsonObject[CONTENT_URL_JSON_KEY] = _contentURL.absoluteString; + } + + return jsonObject; } + (instancetype)instanceFromJsonObject:(id)json { diff --git a/src/ios/JS/CDVPluginResult+HCPEvents.m b/src/ios/JS/CDVPluginResult+HCPEvents.m index 8300cec4..e42d0e4e 100644 --- a/src/ios/JS/CDVPluginResult+HCPEvents.m +++ b/src/ios/JS/CDVPluginResult+HCPEvents.m @@ -72,7 +72,14 @@ + (NSDictionary *)constructErrorBlock:(NSError *)error { * @return JSON dictionary with user data */ + (NSDictionary *)constructDataBlock:(HCPApplicationConfig *)appConfig { - return @{DATA_USER_INFO_CONFIG: [appConfig toJson]}; + NSMutableDictionary *dataBlockDict = [[NSMutableDictionary alloc] initWithDictionary:@{DATA_USER_INFO_CONFIG: @{}}]; + + id appConfigJsonObject = [appConfig toJson]; + if (appConfigJsonObject) { + return dataBlockDict[DATA_USER_INFO_CONFIG] = appConfigJsonObject; + } + + return dataBlockDict; } @end diff --git a/src/ios/Utils/NSBundle+HCPExtension.m b/src/ios/Utils/NSBundle+HCPExtension.m index 3463f190..47bddccd 100644 --- a/src/ios/Utils/NSBundle+HCPExtension.m +++ b/src/ios/Utils/NSBundle+HCPExtension.m @@ -16,7 +16,7 @@ @implementation NSBundle (HCPExtension) + (NSInteger)applicationBuildVersion { NSBundle *mainBundle = [NSBundle mainBundle]; - id appBuildVersion = [mainBundle objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey]; + id appBuildVersion = [mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; if (appBuildVersion == nil) { return 0; }