From c348ab8eb03f82c20c81ceaeff8979da2d33b8d4 Mon Sep 17 00:00:00 2001 From: Parvesh Date: Thu, 22 Jun 2023 12:43:55 +0400 Subject: [PATCH 1/5] use interfaceOrientation for ios 13+ --- src/ios/CameraRenderController.m | 15 +++++++++++++-- src/ios/CameraSessionManager.m | 9 ++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ios/CameraRenderController.m b/src/ios/CameraRenderController.m index 654db04..2a7524d 100644 --- a/src/ios/CameraRenderController.m +++ b/src/ios/CameraRenderController.m @@ -46,7 +46,13 @@ - (void) viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appplicationIsActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteredForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; - UIInterfaceOrientation orientation= [UIApplication sharedApplication].statusBarOrientation; + UIInterfaceOrientation orientation; + if (@available(iOS 13.0, *)) { + UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; + orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; + } else { + orientation= [UIApplication sharedApplication].statusBarOrientation; + } dispatch_async(self.sessionManager.sessionQueue, ^{ if (!self.sessionManager.session.running){ NSLog(@"Starting session from viewWillAppear"); @@ -171,7 +177,12 @@ -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id context) { - toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; + if (@available(iOS 13.0, *)) { + UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; + toInterfaceOrientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; + } else { + toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; + } } completion:^(id context) { [self.sessionManager updateOrientation:[self.sessionManager getCurrentOrientation:toInterfaceOrientation]]; }]; diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index 4df694f..6537a90 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -15,7 +15,14 @@ - (CameraSessionManager *)init { } - (AVCaptureVideoOrientation) getCurrentOrientation { - return [self getCurrentOrientation: [[UIApplication sharedApplication] statusBarOrientation]]; + UIInterfaceOrientation orientation; + if (@available(iOS 13.0, *)) { + UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; + orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; + } else { + orientation= [UIApplication sharedApplication].statusBarOrientation; + } + return [self getCurrentOrientation: orientation]; } - (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation { From 3b04bbb780d9e3b6027440b14db134c108e6c94a Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Mon, 26 Jun 2023 12:10:10 +0400 Subject: [PATCH 2/5] add proper spacing --- src/ios/CameraRenderController.m | 2 +- src/ios/CameraSessionManager.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/CameraRenderController.m b/src/ios/CameraRenderController.m index 2a7524d..8d4df03 100644 --- a/src/ios/CameraRenderController.m +++ b/src/ios/CameraRenderController.m @@ -51,7 +51,7 @@ - (void) viewWillAppear:(BOOL)animated { UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; } else { - orientation= [UIApplication sharedApplication].statusBarOrientation; + orientation = [UIApplication sharedApplication].statusBarOrientation; } dispatch_async(self.sessionManager.sessionQueue, ^{ if (!self.sessionManager.session.running){ diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index 6537a90..25e9cad 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -20,7 +20,7 @@ - (AVCaptureVideoOrientation) getCurrentOrientation { UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; } else { - orientation= [UIApplication sharedApplication].statusBarOrientation; + orientation = [UIApplication sharedApplication].statusBarOrientation; } return [self getCurrentOrientation: orientation]; } From 571031111ce333d6c72427c41b8cca017988124b Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 29 Jun 2023 15:14:56 +0400 Subject: [PATCH 3/5] no repeating code --- src/ios/CameraRenderController.m | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ios/CameraRenderController.m b/src/ios/CameraRenderController.m index 8d4df03..69931f7 100644 --- a/src/ios/CameraRenderController.m +++ b/src/ios/CameraRenderController.m @@ -46,13 +46,7 @@ - (void) viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appplicationIsActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteredForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; - UIInterfaceOrientation orientation; - if (@available(iOS 13.0, *)) { - UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; - orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; - } else { - orientation = [UIApplication sharedApplication].statusBarOrientation; - } + UIInterfaceOrientation orientation = [self getOrientation]; dispatch_async(self.sessionManager.sessionQueue, ^{ if (!self.sessionManager.session.running){ NSLog(@"Starting session from viewWillAppear"); @@ -177,15 +171,20 @@ -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id context) { - if (@available(iOS 13.0, *)) { - UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; - toInterfaceOrientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; - } else { - toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; - } + toInterfaceOrientation = [self getOrientation]; + } completion:^(id context) { [self.sessionManager updateOrientation:[self.sessionManager getCurrentOrientation:toInterfaceOrientation]]; }]; } +- (UIInterfaceOrientation) getOrientation { + if (@available(iOS 13.0, *)) { + UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; + return [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; + } else { + return [[UIApplication sharedApplication] statusBarOrientation]; + } +} + @end From 502683c1fb5b96e94df0eb433fc0a866e6c78bdc Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 30 Jun 2023 13:02:12 +0400 Subject: [PATCH 4/5] one common method --- src/ios/CameraRenderController.m | 13 ++----------- src/ios/CameraSessionManager.h | 1 + src/ios/CameraSessionManager.m | 17 ++++++++++------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/ios/CameraRenderController.m b/src/ios/CameraRenderController.m index 69931f7..26b7296 100644 --- a/src/ios/CameraRenderController.m +++ b/src/ios/CameraRenderController.m @@ -46,12 +46,12 @@ - (void) viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appplicationIsActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteredForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; - UIInterfaceOrientation orientation = [self getOrientation]; dispatch_async(self.sessionManager.sessionQueue, ^{ if (!self.sessionManager.session.running){ NSLog(@"Starting session from viewWillAppear"); [self.sessionManager.session startRunning]; } + UIInterfaceOrientation orientation = [self.sessionManager getOrientation]; [self.sessionManager updateOrientation:[self.sessionManager getCurrentOrientation: orientation]]; }); } @@ -171,20 +171,11 @@ -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id context) { - toInterfaceOrientation = [self getOrientation]; + toInterfaceOrientation = [self.sessionManager getOrientation]; } completion:^(id context) { [self.sessionManager updateOrientation:[self.sessionManager getCurrentOrientation:toInterfaceOrientation]]; }]; } -- (UIInterfaceOrientation) getOrientation { - if (@available(iOS 13.0, *)) { - UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; - return [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; - } else { - return [[UIApplication sharedApplication] statusBarOrientation]; - } -} - @end diff --git a/src/ios/CameraSessionManager.h b/src/ios/CameraSessionManager.h index 0ee2876..c0b006b 100644 --- a/src/ios/CameraSessionManager.h +++ b/src/ios/CameraSessionManager.h @@ -11,6 +11,7 @@ - (void) updateOrientation:(AVCaptureVideoOrientation)orientation; - (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation; + (AVCaptureSessionPreset) calculateResolution:(NSInteger)targetSize; +- (UIInterfaceOrientation) getOrientation; @property (atomic) CIFilter *ciFilter; @property (nonatomic) NSLock *filterLock; diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index 25e9cad..bc8791c 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -15,13 +15,7 @@ - (CameraSessionManager *)init { } - (AVCaptureVideoOrientation) getCurrentOrientation { - UIInterfaceOrientation orientation; - if (@available(iOS 13.0, *)) { - UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; - orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; - } else { - orientation = [UIApplication sharedApplication].statusBarOrientation; - } + UIInterfaceOrientation orientation = [self getOrientation]; return [self getCurrentOrientation: orientation]; } @@ -202,4 +196,13 @@ - (AVCaptureDevice *) cameraWithPosition:(AVCaptureDevicePosition) position { return nil; } +- (UIInterfaceOrientation) getOrientation { + if (@available(iOS 13.0, *)) { + UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject]; + return [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait; + } else { + return [[UIApplication sharedApplication] statusBarOrientation]; + } +} + @end From f1c27438fc488b86cbe6aaa43f71ea5981779aa6 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 4 Jul 2023 09:49:24 +0400 Subject: [PATCH 5/5] update version to 2.0.17 --- CHANGELOG.md | 6 +++++- package-lock.json | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c33bbc..971b377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +## [2.0.17](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.16...v2.0.17) (2023-07-04) + +* **iOS:** Use interfaceOrientation for ios 13+. ([#67](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/pull/67)) + ## [2.0.16](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.15...v2.0.16) (2023-05-08) -* **iOS:** Added a NSNotification observer to check if app is interrupted by a drawer app on ipad. ([#64](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/pull/66)) +* **iOS:** Added a NSNotification observer to check if app is interrupted by a drawer app on ipad. ([#66](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/pull/66)) ## [2.0.15](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.14...v2.0.15) (2023-01-30) diff --git a/package-lock.json b/package-lock.json index 528033f..a2cf1fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spoonconsulting/cordova-plugin-simple-camera-preview", - "version": "2.0.16", + "version": "2.0.17", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spoonconsulting/cordova-plugin-simple-camera-preview", - "version": "2.0.16", + "version": "2.0.17", "license": "Apache 2.0", "devDependencies": {} } diff --git a/package.json b/package.json index 3c4572b..f793732 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spoonconsulting/cordova-plugin-simple-camera-preview", - "version": "2.0.16", + "version": "2.0.17", "description": "Cordova plugin that allows camera interaction from HTML code for showing camera preview below or on top of the HTML.", "keywords": [ "cordova", diff --git a/plugin.xml b/plugin.xml index d99b832..6d78762 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ - + cordova-plugin-simple-camera-preview Cordova plugin that allows camera interaction from HTML code. Show camera preview popup on top of the HTML.