From a2e45c5b6e2c757f37c2d1dfda402f0dc42e880e Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 22 Mar 2024 12:27:19 +0400 Subject: [PATCH] ios plugin refactoring --- src/ios/CameraSessionManager.m | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index 39d3a33..0183542 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -185,12 +185,13 @@ - (void)switchToUltraWideCamera:(NSString*)cameraMode completion:(void (^)(BOOL } dispatch_async(self.sessionQueue, ^{ + BOOL cameraSwitched = FALSE; if (@available(iOS 13.0, *)) { AVCaptureDevice *ultraWideCamera; - if([cameraMode isEqualToString:@"default"]) { - ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera]; - } else { + if([cameraMode isEqualToString:@"wide-angle"]) { ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInUltraWideCamera]; + } else { + ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera]; } if (ultraWideCamera) { // Remove the current input @@ -210,33 +211,21 @@ - (void)switchToUltraWideCamera:(NSString*)cameraMode completion:(void (^)(BOOL orientation = [self getCurrentOrientation]; }); [self updateOrientation:orientation]; - if (completion) { - completion(YES); - } + cameraSwitched = TRUE; } else { NSLog(@"Failed to add ultra-wide input to session"); - if (completion) { - completion(NO); - } } } else { NSLog(@"Error creating ultra-wide device input: %@", error.localizedDescription); - if (completion) { - completion(NO); - } } } else { NSLog(@"Ultra-wide camera not found"); - if (completion) { - completion(NO); - } } } else { // Fallback on earlier versions - if (completion) { - completion(NO); - } } + + completion ? completion(cameraSwitched): NULL; }); }