Updated Branches:
  refs/heads/2.6.x ebc74ec75 -> c9be68b4e

[CB-2732] Only set camera device when allowed.

The camera device can only be set when the source type is
UIImagePickerControllerSourceTypeCamera (ie. we're actually using the
camera).

This is an intentional redux of
8d285676fcab25da70918d27d3b37210909d3e46.

There's also some uncrustification in here.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c9be68b4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c9be68b4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c9be68b4

Branch: refs/heads/2.6.x
Commit: c9be68b4e54f470903f7ee9eb42d8942e51bc487
Parents: ebc74ec
Author: Max Woghiren <[email protected]>
Authored: Wed Apr 3 17:31:09 2013 -0400
Committer: Max Woghiren <[email protected]>
Committed: Thu Apr 4 11:39:54 2013 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.m |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c9be68b4/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index c3e053e..823fde9 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -85,12 +85,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
         return;
     }
 
-    NSNumber* cameraDirection = [arguments objectAtIndex:11];
-    UIImagePickerControllerCameraDevice cameraDevice = 
UIImagePickerControllerCameraDeviceRear; // default
-    if (cameraDirection != nil) {
-        cameraDevice = (UIImagePickerControllerSourceType)[cameraDirection 
intValue];
-    }
-
     bool allowEdit = [[arguments objectAtIndex:7] boolValue];
     NSNumber* targetWidth = [arguments objectAtIndex:3];
     NSNumber* targetHeight = [arguments objectAtIndex:4];
@@ -114,7 +108,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
 
     cameraPicker.delegate = self;
     cameraPicker.sourceType = sourceType;
-    cameraPicker.cameraDevice = cameraDevice;
     cameraPicker.allowsEditing = allowEdit; // THIS IS ALL IT TAKES FOR 
CROPPING - jm
     cameraPicker.callbackId = callbackId;
     cameraPicker.targetSize = targetSize;
@@ -132,18 +125,22 @@ static NSSet* org_apache_cordova_validArrowDirections;
     cameraPicker.returnType = ([arguments objectAtIndex:1]) ? [[arguments 
objectAtIndex:1] intValue] : DestinationTypeFileUri;
 
     if (sourceType == UIImagePickerControllerSourceTypeCamera) {
-        // we only allow taking pictures (no video) in this api
+        // We only allow taking pictures (no video) in this API.
         cameraPicker.mediaTypes = [NSArray 
arrayWithObjects:(NSString*)kUTTypeImage, nil];
+
+        // We can only set the camera device if we're actually using the 
camera.
+        NSNumber* cameraDirection = [command argumentAtIndex:11 
withDefault:[NSNumber 
numberWithInteger:UIImagePickerControllerCameraDeviceRear]];
+        cameraPicker.cameraDevice = 
(UIImagePickerControllerCameraDevice)[cameraDirection intValue];
     } else if (mediaType == MediaTypeAll) {
         cameraPicker.mediaTypes = [UIImagePickerController 
availableMediaTypesForSourceType:sourceType];
     } else {
-        NSArray* mediaArray = [NSArray arrayWithObjects:(NSString*)(mediaType 
== MediaTypeVideo ? kUTTypeMovie:kUTTypeImage), nil];
+        NSArray* mediaArray = [NSArray arrayWithObjects:(NSString*)(mediaType 
== MediaTypeVideo ? kUTTypeMovie : kUTTypeImage), nil];
         cameraPicker.mediaTypes = mediaArray;
     }
 
     if ([self popoverSupported] && (sourceType != 
UIImagePickerControllerSourceTypeCamera)) {
         if (cameraPicker.popoverController == nil) {
-            cameraPicker.popoverController = [[NSClassFromString 
(@"UIPopoverController")alloc] initWithContentViewController:cameraPicker];
+            cameraPicker.popoverController = 
[[NSClassFromString(@"UIPopoverController")alloc] 
initWithContentViewController:cameraPicker];
         }
         NSDictionary* options = [command.arguments objectAtIndex:10 
withDefault:nil];
         [self displayPopover:options];
@@ -299,18 +296,17 @@ static NSSet* org_apache_cordova_validArrowDirections;
                 data = UIImagePNGRepresentation(scaledImage == nil ? image : 
scaledImage);
             } else {
                 data = UIImageJPEGRepresentation(scaledImage == nil ? image : 
scaledImage, cameraPicker.quality / 100.0f);
-                
+
                 /* splice loc */
-                CDVJpegHeaderWriter * exifWriter = [[CDVJpegHeaderWriter 
alloc] init];
-                NSString * headerstring = [exifWriter createExifAPP1: [info 
objectForKey:@"UIImagePickerControllerMediaMetadata"]];
+                CDVJpegHeaderWriter* exifWriter = [[CDVJpegHeaderWriter alloc] 
init];
+                NSString* headerstring = [exifWriter createExifAPP1:[info 
objectForKey:@"UIImagePickerControllerMediaMetadata"]];
                 data = [exifWriter spliceExifBlockIntoJpeg:data 
withExifBlock:headerstring];
-                
             }
 
             if (cameraPicker.returnType == DestinationTypeFileUri) {
                 // write to temp directory and return URI
                 // get the temp directory path
-                NSString* docsPath = [NSTemporaryDirectory 
()stringByStandardizingPath];
+                NSString* docsPath = 
[NSTemporaryDirectory()stringByStandardizingPath];
                 NSError* err = nil;
                 NSFileManager* fileMgr = [[NSFileManager alloc] init]; // 
recommended by apple (vs [NSFileManager defaultManager]) to be threadsafe
                 // generate unique file name
@@ -435,7 +431,7 @@ static NSSet* org_apache_cordova_validArrowDirections;
             rotation_radians = 0.0;
             break;
 
-        case UIImageOrientationDown :
+        case UIImageOrientationDown:
             rotation_radians = M_PI; // don't be scared of radians, if you're 
reading this, you're good at math
             break;
 
@@ -534,7 +530,7 @@ static NSSet* org_apache_cordova_validArrowDirections;
     // first parameter an image
     [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", 
boundary] dataUsingEncoding:NSUTF8StringEncoding]];
     [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: 
form-data; name=\"upload\"; filename=\"%@\"\r\n", filename] 
dataUsingEncoding:NSUTF8StringEncoding]];
-    [postBody appendData:[@"Content-Type: image/png\r\n\r\n" 
dataUsingEncoding:NSUTF8StringEncoding]];
+    [postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding 
: NSUTF8StringEncoding]];
     [postBody appendData:imageData];
 
     // // second parameter information

Reply via email to