Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support configuration options in iOS, bugfix to prevent crashes #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions src/ios/CDVBarcodeScanner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,46 @@ @implementation CDVbcsProcessor
- (id)initWithPlugin:(CDVBarcodeScanner*)plugin
callback:(NSString*)callback
parentViewController:(UIViewController*)parentViewController
alterateOverlayXib:(NSString *)alternateXib {
alterateOverlayXib:(NSObject *)config {
self = [super init];
if (!self) return self;

self.plugin = plugin;
self.callback = callback;
self.parentViewController = parentViewController;
self.alternateXib = alternateXib;

// use configuration options to set path for an alternate overlay Xib
if([config isKindOfClass:[NSString class]]) {

self.alternateXib = (NSString *)config;

} else if([config isKindOfClass:[NSDictionary class]]) {

NSDictionary *dict = (NSDictionary *)config;
NSArray *keys = [dict allKeys];
NSString *keyname;
NSObject *keyvalue;
NSString *keyvaluestr;
NSNumber *keyvaluenum;

for(int i=0; i<[keys count]; i++) {
keyname = [keys objectAtIndex:i];
keyvalue = [dict objectForKey:keyname];

if([keyvalue isKindOfClass:[NSString class]]) {
keyvaluestr = (NSString *)keyvalue;
} else if([keyvalue isKindOfClass:[NSNumber class]]) {
keyvaluenum = (NSNumber *)keyvalue;
}

// Add additional configuration options here //

if([keyname isEqualToString:@"alternateXib"]) {
self.alternateXib = keyvaluestr;
}
}

}

self.is1D = YES;
self.is2D = YES;
Expand Down Expand Up @@ -844,7 +876,11 @@ - (void)flipCameraButtonPressed:(id)sender
//--------------------------------------------------------------------------
- (UIView *)buildOverlayViewFromXib
{
[[NSBundle mainBundle] loadNibNamed:self.alternateXib owner:self options:NULL];
@try {
[[NSBundle mainBundle] loadNibNamed:self.alternateXib owner:self options:NULL];
} @catch(NSException *e) {
NSLog(@"Exception: %@", e);
}

if ( self.overlayView == nil )
{
Expand Down