Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Added some additional nil handling. Relates to #13
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Oct 1, 2015
1 parent 9636a8a commit 0456ffc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/ios/Config/HCPApplicationConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 20 additions & 5 deletions src/ios/Config/HCPContentConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion src/ios/JS/CDVPluginResult+HCPEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/ios/Utils/NSBundle+HCPExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0456ffc

Please sign in to comment.