diff --git a/src/ios/CameraSessionManager.h b/src/ios/CameraSessionManager.h index 8856e52..b449940 100644 --- a/src/ios/CameraSessionManager.h +++ b/src/ios/CameraSessionManager.h @@ -8,7 +8,8 @@ - (void) setupSession:(NSString *)defaultCamera completion:(void(^)(BOOL started))completion options:(NSDictionary *)options photoSettings:(AVCapturePhotoSettings *)photoSettings; - (void) setFlashMode:(NSInteger)flashMode photoSettings:(AVCapturePhotoSettings *)photoSettings; - (void) torchSwitch:(NSInteger)torchState; -- (BOOL) switchToUltraWideCamera; +- (BOOL) switchToUltraWideCamera:(NSString *)cameraMode; +- (BOOL) deviceHasUltraWideCamera; - (void) updateOrientation:(AVCaptureVideoOrientation)orientation; - (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation; + (AVCaptureSessionPreset) calculateResolution:(NSInteger)targetSize; diff --git a/src/ios/CameraSessionManager.m b/src/ios/CameraSessionManager.m index b356e1d..30dc1d6 100644 --- a/src/ios/CameraSessionManager.m +++ b/src/ios/CameraSessionManager.m @@ -176,12 +176,17 @@ - (void) torchSwitch:(NSInteger)torchState{ } } -- (BOOL)switchToUltraWideCamera { +- (BOOL)switchToUltraWideCamera:(NSString*)cameraMode { if (![self deviceHasUltraWideCamera]) return FALSE; dispatch_async(self.sessionQueue, ^{ if (@available(iOS 13.0, *)) { - AVCaptureDevice *ultraWideCamera = [self cameraWithPosition: self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInUltraWideCamera]; + AVCaptureDevice *ultraWideCamera; + if([cameraMode isEqual: @"default"]){ + ultraWideCamera = [self cameraWithPosition: self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera]; + } else { + ultraWideCamera = [self cameraWithPosition: self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera]; + } if (ultraWideCamera) { // Remove the current input [self.session removeInput:self.videoDeviceInput]; diff --git a/src/ios/SimpleCameraPreview.h b/src/ios/SimpleCameraPreview.h index bdc81a6..8ddbc69 100644 --- a/src/ios/SimpleCameraPreview.h +++ b/src/ios/SimpleCameraPreview.h @@ -17,6 +17,7 @@ - (void) setSize:(CDVInvokedUrlCommand*)command; - (void) torchSwitch: (CDVInvokedUrlCommand*)command; - (void) switchToUltraWideCamera: (CDVInvokedUrlCommand*) command; +- (void) deviceHasUltraWideCamera: (CDVInvokedUrlCommand*) command; - (void) deviceHasFlash: (CDVInvokedUrlCommand*)command; @property (nonatomic) CameraSessionManager *sessionManager; @property (nonatomic) CameraRenderController *cameraRenderController; diff --git a/src/ios/SimpleCameraPreview.m b/src/ios/SimpleCameraPreview.m index 1a3ea35..efd5bcf 100644 --- a/src/ios/SimpleCameraPreview.m +++ b/src/ios/SimpleCameraPreview.m @@ -157,13 +157,23 @@ - (void) torchSwitch:(CDVInvokedUrlCommand*)command{ } - (void) switchToUltraWideCamera:(CDVInvokedUrlCommand*)command{ + NSString *device = [command.arguments objectAtIndex:0]; if (self.sessionManager != nil) { - [self.sessionManager switchToUltraWideCamera]; + [self.sessionManager switchToUltraWideCamera: device]; } CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +- (void) deviceHasUltraWideCamera:(CDVInvokedUrlCommand *)command{ + BOOL hasUltraWideCamera = NO; + if (self.sessionManager != nil) { + hasUltraWideCamera = [self.sessionManager deviceHasUltraWideCamera]; + } + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:hasUltraWideCamera]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + - (void) deviceHasFlash:(CDVInvokedUrlCommand*)command{ AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera] mediaType:AVMediaTypeVideo diff --git a/www/SimpleCameraPreview.js b/www/SimpleCameraPreview.js index 4366c4c..4bf5f1f 100755 --- a/www/SimpleCameraPreview.js +++ b/www/SimpleCameraPreview.js @@ -28,14 +28,20 @@ SimpleCameraPreview.torchSwitch = function (options, onSuccess, onError) { exec(onSuccess, onError, PLUGIN_NAME, "torchSwitch", [options]); }; -SimpleCameraPreview.switchToUltraWideCamera = function (onSuccess, onError) { - exec(onSuccess, onError, PLUGIN_NAME, "switchToUltraWideCamera", []); +SimpleCameraPreview.switchToUltraWideCamera = function (options, onSuccess, onError) { + options = options || {}; + options.captureDevice = options.captureDevice || "default"; + exec(onSuccess, onError, PLUGIN_NAME, "switchToUltraWideCamera", [options.captureDevice]); }; SimpleCameraPreview.deviceHasFlash = function (onSuccess, onError) { exec(onSuccess, onError, PLUGIN_NAME, "deviceHasFlash", []); }; +SimpleCameraPreview.deviceHasUltraWideCamera = function (onSuccess, onError) { + exec(onSuccess, onError, PLUGIN_NAME, "deviceHasUltraWideCamera", []); +}; + SimpleCameraPreview.getMinZoomRatio = function (onSuccess, onError) { exec(onSuccess, onError, PLUGIN_NAME, "getMinZoomRatio", []); };