Skip to content

Commit

Permalink
Merge pull request #8 from OutSystems/fix/RNMT-3309/caption-characters
Browse files Browse the repository at this point in the history
RNMT-3309 [InAppBrowser] App crashes in iOS when caption is only numbers
  • Loading branch information
usernuno authored Oct 1, 2019
2 parents 6287c06 + 7100539 commit 9fd7303
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/ios/CDVInAppBrowserOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Licensed to the Apache Software Foundation (ASF) under one

#import "CDVInAppBrowserOptions.h"

#import <objc/runtime.h>

@implementation CDVInAppBrowserOptions

- (id)init
Expand Down Expand Up @@ -69,19 +71,22 @@ + (CDVInAppBrowserOptions*)parseOptions:(NSString*)options
NSString* value = [keyvalue objectAtIndex:1];
NSString* value_lc = [value lowercaseString];

BOOL isBoolean = [value_lc isEqualToString:@"yes"] || [value_lc isEqualToString:@"no"];
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setAllowsFloats:YES];
BOOL isNumber = [numberFormatter numberFromString:value_lc] != nil;

// set the property according to the key name
if ([obj respondsToSelector:NSSelectorFromString(key)]) {
if (isNumber) {
[obj setValue:[numberFormatter numberFromString:value_lc] forKey:key];
} else if (isBoolean) {
[obj setValue:[NSNumber numberWithBool:[value_lc isEqualToString:@"yes"]] forKey:key];
} else {
[obj setValue:value forKey:key];
NSString *attributes = [self attributesOfPropertyNamed:key];
if (attributes) {

if ([attributes hasPrefix:@"TB,"]) {
[obj setValue:[NSNumber numberWithBool:[value_lc isEqualToString:@"yes"]] forKey:key];

} else if ([attributes hasPrefix:@"T@\"NSNumber\","]) {
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setAllowsFloats:YES];
[obj setValue:[numberFormatter numberFromString:value_lc] forKey:key];

} else if ([attributes hasPrefix:@"T@\"NSString\","]) {
[obj setValue:value forKey:key];
}
}
}
}
Expand All @@ -90,4 +95,9 @@ + (CDVInAppBrowserOptions*)parseOptions:(NSString*)options
return obj;
}

+ (NSString*)attributesOfPropertyNamed:(NSString*)propertyName {
objc_property_t property = class_getProperty([self class], [propertyName UTF8String]);
return property ? [NSString stringWithCString:property_getAttributes(property) encoding:NSUTF8StringEncoding] : nil;
}

@end

0 comments on commit 9fd7303

Please sign in to comment.