Skip to content

Commit

Permalink
fixes iOS 12.+ crushes
Browse files Browse the repository at this point in the history
  • Loading branch information
Narush Dzianis committed Jun 21, 2019
1 parent fc5dcc3 commit c677546
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions ios/CsZBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

#pragma mark - Plugin API

+ (UIView*) searchToolbarFrom:(UIView*) topView {
UIView* result = nil;
for (UIView* testView in topView.subviews) {
if([testView isKindOfClass:[UIToolbar class]]){
result = testView;
break;
} else {
if ([testView.subviews count] > 0){
result = [self searchToolbarFrom:testView];
if (result != nil){
break;
}
}
}
}
return result;
};

- (void)scan: (CDVInvokedUrlCommand*)command;
{
if (self.scanInProgress) {
Expand All @@ -49,7 +67,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
self.scanReader = [AlmaZBarReaderViewController new];

self.scanReader.readerDelegate = self;
self.scanReader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
self.scanReader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait || UIDeviceOrientationLandscapeRight || UIDeviceOrientationLandscapeLeft);

// Get user parameters
NSDictionary *params = (NSDictionary*) [command argumentAtIndex:0];
Expand All @@ -72,16 +90,22 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
}

// Hack to hide the bottom bar's Info button... originally based on http://stackoverflow.com/a/16353530
NSInteger infoButtonIndex;
if ([[[UIDevice currentDevice] systemVersion] compare:@"10.0" options:NSNumericSearch] != NSOrderedAscending) {
infoButtonIndex = 1;
} else {
infoButtonIndex = 3;

UIView* testView = self.scanReader.view;
UIView* toolBar = [[self class] searchToolbarFrom:testView];

for (UIBarButtonItem* item in ((UIToolbar*)toolBar).items) {
if (item.customView != nil){
if([item.customView isKindOfClass:[UIButton class]]){
UIButton* but = (UIButton*)item.customView;
if (but.buttonType == UIButtonTypeInfoLight
|| but.buttonType == UIButtonTypeInfoDark){
but.hidden = YES;
}
}
}
}
UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:infoButtonIndex];
[infoButton setHidden:YES];

//UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"Press Me" forState:UIControlStateNormal]; [button sizeToFit]; [self.view addSubview:button];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
Expand Down

0 comments on commit c677546

Please sign in to comment.