From 63e89cbf62a447d50a5905559c8d2cd1cb3662a8 Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 15 Jun 2016 09:30:58 +0200 Subject: [PATCH 1/2] add camera direction option and constants --- README.md | 2 ++ www/capture.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 28580b04..418c3d52 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a ### Properties - __limit__: The maximum number of images the user can capture in a single capture operation. The value must be greater than or equal to 1 (defaults to 1). +- __cameraDirection__: Direction of the camera (Camera.CAMERA_FRONT|Camera.CAMERA_BACK) (defaults to Camera.CAMERA_BACK) **This only works on iOS** ### Example @@ -357,6 +358,7 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a - __limit__: The maximum number of video clips the device's user can capture in a single capture operation. The value must be greater than or equal to 1 (defaults to 1). - __duration__: The maximum duration of a video clip, in seconds. +- __cameraDirection__: Direction of the camera (Camera.CAMERA_FRONT|Camera.CAMERA_BACK) (defaults to Camera.CAMERA_BACK) **This only works on iOS** ### Example diff --git a/www/capture.js b/www/capture.js index 11c916b8..6036ba90 100644 --- a/www/capture.js +++ b/www/capture.js @@ -47,6 +47,12 @@ function Capture() { this.supportedVideoModes = []; } +/** + * Camera direction constants + */ +Capture.CAMERA_BACK = 0; +Capture.CAMERA_FRONT = 1; + /** * Launch audio recorder application for recording audio clip(s). * From 94709ace5174b7fc59fd97574834788183b98e6b Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 15 Jun 2016 09:57:31 +0200 Subject: [PATCH 2/2] implement camera direction in ios --- src/ios/CDVCapture.m | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index 53e1b2b9..265b4c7b 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -58,17 +58,17 @@ - (uint64_t)accessibilityTraits - (BOOL)prefersStatusBarHidden { return YES; } - + - (UIViewController*)childViewControllerForStatusBarHidden { return nil; } - + - (void)viewWillAppear:(BOOL)animated { SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate"); if ([self respondsToSelector:sel]) { [self performSelector:sel withObject:nil afterDelay:0]; } - + [super viewWillAppear:animated]; } @@ -131,6 +131,7 @@ - (void)captureImage:(CDVInvokedUrlCommand*)command // options could contain limit and mode neither of which are supported at this time // taking more than one picture (limit) is only supported if provide own controls via cameraOverlayView property // can support mode in OS + NSNumber* cameraDirection = [options objectForKey:@"cameraDirection"]; if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { NSLog(@"Capture.imageCapture: camera not available."); @@ -144,6 +145,11 @@ - (void)captureImage:(CDVInvokedUrlCommand*)command pickerController.delegate = self; pickerController.sourceType = UIImagePickerControllerSourceTypeCamera; pickerController.allowsEditing = NO; + + if([cameraDirection intValue] == 1) { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; + } + if ([pickerController respondsToSelector:@selector(mediaTypes)]) { // iOS 3.0 pickerController.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage, nil]; @@ -222,6 +228,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // options could contain limit, duration and mode // taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property NSNumber* duration = [options objectForKey:@"duration"]; + NSNumber* cameraDirection = [options objectForKey:@"cameraDirection"]; NSString* mediaType = nil; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { @@ -253,6 +260,10 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // iOS 3.0 pickerController.mediaTypes = [NSArray arrayWithObjects:mediaType, nil]; + if([cameraDirection intValue] == 1) { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; + } + if ([mediaType isEqualToString:(NSString*)kUTTypeMovie]){ if (duration) { pickerController.videoMaximumDuration = [duration doubleValue]; @@ -337,7 +348,7 @@ - (void)getMediaModes:(CDVInvokedUrlCommand*)command movieArray ? (NSObject*) movieArray:[NSNull null], @"video", audioArray ? (NSObject*) audioArray:[NSNull null], @"audio", nil]; - + NSData* jsonData = [NSJSONSerialization dataWithJSONObject:modes options:0 error:nil]; NSString* jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; @@ -608,7 +619,7 @@ - (void)loadView if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { self.edgesForExtendedLayout = UIRectEdgeNone; } - + // create view and display CGRect viewRect = [[UIScreen mainScreen] applicationFrame]; UIView* tmp = [[UIView alloc] initWithFrame:viewRect]; @@ -737,7 +748,7 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations { UIInterfaceOrientationMask orientation = UIInterfaceOrientationMaskPortrait; UIInterfaceOrientationMask supported = [captureCommand.viewController supportedInterfaceOrientations]; - + orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown); return orientation; } @@ -746,7 +757,7 @@ - (NSUInteger)supportedInterfaceOrientations { NSUInteger orientation = UIInterfaceOrientationMaskPortrait; // must support portrait NSUInteger supported = [captureCommand.viewController supportedInterfaceOrientations]; - + orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown); return orientation; } @@ -773,7 +784,7 @@ - (void)processButton:(id)sender __block NSError* error = nil; __weak CDVAudioRecorderViewController* weakSelf = self; - + void (^startRecording)(void) = ^{ [weakSelf.avSession setCategory:AVAudioSessionCategoryRecord error:&error]; [weakSelf.avSession setActive:YES error:&error]; @@ -794,7 +805,7 @@ - (void)processButton:(id)sender } UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); }; - + SEL rrpSel = NSSelectorFromString(@"requestRecordPermission:"); if ([self.avSession respondsToSelector:rrpSel]) {