Skip to content

Commit d9e3e3f

Browse files
authored
fix: fix iOS build warnings (#79)
1 parent c010446 commit d9e3e3f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

ios/IdscanSdk.m

+12-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ @implementation IdscanSdk
3131
[[NSUserDefaults standardUserDefaults] synchronize];
3232

3333
dispatch_async(dispatch_get_main_queue(), ^(void) {
34-
ScannerViewController* scannerViewController = [[ScannerViewController alloc] init];
34+
ScannerViewController *scannerViewController = [[ScannerViewController alloc] init];
3535
scannerViewController.delegate = self;
3636
NSLog(@"IDScanner: Starting camera scanner...");
37-
38-
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
37+
38+
UIWindow *windowRoot = nil;
39+
NSArray *windows = [[UIApplication sharedApplication] windows];
40+
for (UIWindow *window in windows) {
41+
if (window.isKeyWindow) {
42+
windowRoot = window;
43+
break;
44+
}
45+
}
46+
47+
UIViewController *rootViewController = [windowRoot rootViewController];
3948
[rootViewController presentViewController:scannerViewController animated:YES completion:nil];
4049
});
4150
}

ios/ScannerViewController.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ - (void)initCapture
157157

158158
// We add the preview layer
159159
self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
160+
161+
UIWindow *firstWindow = [[[UIApplication sharedApplication] windows] firstObject];
162+
UIWindowScene *windowScene = firstWindow.windowScene;
163+
UIInterfaceOrientation orientation = windowScene.interfaceOrientation;
160164

161-
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
162165
if (orientation == UIInterfaceOrientationLandscapeLeft) {
163166
self.prevLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
164167
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 {
485488
}
486489

487490
- (enum UIInterfaceOrientationMask)supportedInterfaceOrientations {
488-
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
489-
491+
UIWindow *firstWindow = [[[UIApplication sharedApplication] windows] firstObject];
492+
UIWindowScene *windowScene = firstWindow.windowScene;
493+
UIInterfaceOrientation interfaceOrientation = windowScene.interfaceOrientation;
494+
490495
switch (interfaceOrientation) {
491496
case UIInterfaceOrientationPortrait:
492497
return UIInterfaceOrientationMaskPortrait;

0 commit comments

Comments
 (0)