diff --git a/src/ios/CDVCapture.h b/src/ios/CDVCapture.h index c7433a41..30fec18c 100644 --- a/src/ios/CDVCapture.h +++ b/src/ios/CDVCapture.h @@ -31,6 +31,7 @@ enum CDVCaptureError { CAPTURE_PERMISSION_DENIED = 4, CAPTURE_NOT_SUPPORTED = 20 }; + typedef NSUInteger CDVCaptureError; @interface CDVImagePicker : UIImagePickerController @@ -49,8 +50,10 @@ typedef NSUInteger CDVCaptureError; { CDVImagePicker* pickerController; BOOL inUse; + BOOL saveVideoToGallery; } @property BOOL inUse; +@property BOOL saveVideoToGallery; - (void)captureAudio:(CDVInvokedUrlCommand*)command; - (void)captureImage:(CDVInvokedUrlCommand*)command; - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId; @@ -117,3 +120,5 @@ typedef NSUInteger CDVCaptureError; - (NSString*)formatTime:(int)interval; - (void)updateTime; @end + + diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index 3919848a..9d585215 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -76,10 +76,11 @@ - (void)viewWillAppear:(BOOL)animated { @implementation CDVCapture @synthesize inUse; - +@synthesize saveVideoToGallery; - (void)pluginInitialize { self.inUse = NO; + self.saveVideoToGallery = NO; } - (void)captureAudio:(CDVInvokedUrlCommand*)command @@ -213,6 +214,7 @@ - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCal - (void)captureVideo:(CDVInvokedUrlCommand*)command { + NSString* callbackId = command.callbackId; NSDictionary* options = [command argumentAtIndex:0]; @@ -224,6 +226,23 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property NSNumber* duration = [options objectForKey:@"duration"]; NSNumber* quality = [options objectForKey:@"quality"]; + NSNumber* frontFacing = [options objectForKey:@"frontFacing"]; + NSNumber* saveToGallery = [options objectForKey:@"saveToGallery"]; + if(![[options allKeys] containsObject: @"frontFacing"]) { + // set to TRUE as default + frontFacing = [NSNumber numberWithInt: 1]; + } + if([[options allKeys] containsObject: @"saveToGallery"]) { + if ([saveToGallery boolValue]) { + self.saveVideoToGallery = YES; + } else { + self.saveVideoToGallery = NO; + } + } else { + // set to TRUE as default + self.saveVideoToGallery = YES; + } + NSString* mediaType = nil; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { @@ -282,6 +301,11 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } + if ([frontFacing boolValue]) { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; + } else { + pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear; + } // CDVImagePicker specific property pickerController.callbackId = callbackId; pickerController.modalPresentationStyle = UIModalPresentationCurrentContext; @@ -293,13 +317,15 @@ - (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)c { // save the movie to photo album (only avail as of iOS 3.1) - /* don't need, it should automatically get saved - NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)); - if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) { - NSLog(@"try to save movie"); - UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil); - NSLog(@"finished saving movie"); - }*/ + /* don't need, it should automatically get saved*/ + if (self.saveVideoToGallery) { + NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)); + if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) { + NSLog(@"try to save movie"); + UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil); + NSLog(@"finished saving movie"); + } + } // create MediaFile object NSDictionary* fileDict = [self getMediaDictionaryFromPath:moviePath ofType:nil]; NSArray* fileArray = [NSArray arrayWithObject:fileDict]; diff --git a/types/index.d.ts b/types/index.d.ts index 17f53858..27932aad 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -155,6 +155,10 @@ interface VideoOptions { limit?: number; /** The maximum duration of a video clip, in seconds. */ duration?: number; + /** Set 1 in case you want to use front facing camera for video capture. */ + frontFacing?: number; + /** Set 1 in case you want to use save video to gallery for video capture. */ + saveToGallery?: number; } /** Encapsulates a set of media capture parameters that a device supports. */