Updated Branches:
  refs/heads/master 997359f0a -> 60eb7f1f1

[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/60eb7f1f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/60eb7f1f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/60eb7f1f

Branch: refs/heads/master
Commit: 60eb7f1f15820302695e8ac1deb54d1e0a4a2456
Parents: 997359f
Author: Max Woghiren <[email protected]>
Authored: Wed Apr 3 17:31:09 2013 -0400
Committer: Max Woghiren <[email protected]>
Committed: Thu Apr 4 11:19:08 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/60eb7f1f/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