From c677546e640f619454cbe7217564100b013c16e3 Mon Sep 17 00:00:00 2001 From: Narush Dzianis Date: Fri, 21 Jun 2019 14:57:45 +0300 Subject: [PATCH] fixes iOS 12.+ crushes --- ios/CsZBar.m | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/ios/CsZBar.m b/ios/CsZBar.m index 45a15ab..a15f2b2 100644 --- a/ios/CsZBar.m +++ b/ios/CsZBar.m @@ -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) { @@ -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]; @@ -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;