From f34c7b65fa5792dea4012833975e4cec7ea29d11 Mon Sep 17 00:00:00 2001 From: Ian Y Date: Tue, 5 Mar 2024 10:50:52 +0800 Subject: [PATCH] fix: fix iOS build warnings --- ios/IdscanSdk.m | 15 ++++++++++++--- ios/ScannerViewController.m | 11 ++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ios/IdscanSdk.m b/ios/IdscanSdk.m index 58ee3ab..8f8b214 100644 --- a/ios/IdscanSdk.m +++ b/ios/IdscanSdk.m @@ -31,11 +31,20 @@ @implementation IdscanSdk [[NSUserDefaults standardUserDefaults] synchronize]; dispatch_async(dispatch_get_main_queue(), ^(void) { - ScannerViewController* scannerViewController = [[ScannerViewController alloc] init]; + ScannerViewController *scannerViewController = [[ScannerViewController alloc] init]; scannerViewController.delegate = self; NSLog(@"IDScanner: Starting camera scanner..."); - - UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController]; + + UIWindow *windowRoot = nil; + NSArray *windows = [[UIApplication sharedApplication] windows]; + for (UIWindow *window in windows) { + if (window.isKeyWindow) { + windowRoot = window; + break; + } + } + + UIViewController *rootViewController = [windowRoot rootViewController]; [rootViewController presentViewController:scannerViewController animated:YES completion:nil]; }); } diff --git a/ios/ScannerViewController.m b/ios/ScannerViewController.m index 8945878..57bb7ee 100644 --- a/ios/ScannerViewController.m +++ b/ios/ScannerViewController.m @@ -157,8 +157,11 @@ - (void)initCapture // We add the preview layer self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession]; + + UIWindow *firstWindow = [[[UIApplication sharedApplication] windows] firstObject]; + UIWindowScene *windowScene = firstWindow.windowScene; + UIInterfaceOrientation orientation = windowScene.interfaceOrientation; - UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == UIInterfaceOrientationLandscapeLeft) { self.prevLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft; self.prevLayer.frame = CGRectMake(0, 0, MAX(self.view.frame.size.width,self.view.frame.size.height), MIN(self.view.frame.size.width,self.view.frame.size.height)); @@ -485,8 +488,10 @@ - (void)decodeResultNotification: (NSNotification *)notification { } - (enum UIInterfaceOrientationMask)supportedInterfaceOrientations { - UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; - + UIWindow *firstWindow = [[[UIApplication sharedApplication] windows] firstObject]; + UIWindowScene *windowScene = firstWindow.windowScene; + UIInterfaceOrientation interfaceOrientation = windowScene.interfaceOrientation; + switch (interfaceOrientation) { case UIInterfaceOrientationPortrait: return UIInterfaceOrientationMaskPortrait;