Skip to content

Commit

Permalink
handle wide and ultra wide angle camera ios
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Mar 18, 2024
1 parent 44b7fe0 commit 68b0332
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/ios/CameraSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions src/ios/SimpleCameraPreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions www/SimpleCameraPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", []);
};
Expand Down

0 comments on commit 68b0332

Please sign in to comment.