Updated Branches:
  refs/heads/master 29b894298 -> 8be82b9a3

Fixes CB-819 fail callback not invoked

Problem was that on iPad when popover controller is used,
the fail callback was not getting called when the popover was
dismissed w/o picking an image.  Added a delay to the callback to JavaScript
since the app will hang if the callback contains a JavaScript alert.
Also removed clause to close popover from imagePickerDidCancel
because that method is not called when the popover is used.
Also deprecated closePicker since it is not
used within the Cordova code.  Deprecated in the off chance a plugin
is using - will remove in 2.0.


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

Branch: refs/heads/master
Commit: 8be82b9a339b6629adca735c7d1c0c4fa46702e4
Parents: 29b8942
Author: Becky Gibson <becka...@apache.org>
Authored: Mon May 21 17:11:35 2012 -0400
Committer: Becky Gibson <becka...@apache.org>
Committed: Mon May 21 17:29:36 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.h |    2 +-
 CordovaLib/Classes/CDVCamera.m |   20 ++++++++++++--------
 2 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/8be82b9a/CordovaLib/Classes/CDVCamera.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.h b/CordovaLib/Classes/CDVCamera.h
index 9a066ab..6e62232 100644
--- a/CordovaLib/Classes/CDVCamera.h
+++ b/CordovaLib/Classes/CDVCamera.h
@@ -91,7 +91,7 @@ typedef NSUInteger CDVMediaType;
 - (UIImage*)imageByScalingNotCroppingForSize:(UIImage*)anImage 
toSize:(CGSize)frameSize;
 - (UIImage*)imageCorrectedForCaptureOrientation:(UIImage*)anImage;
 
-- (void) closePicker:(CDVCameraPicker*)picker;
+- (void) closePicker:(CDVCameraPicker*)picker __attribute__((deprecated));
 - (void) dealloc;
 
 @end

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/8be82b9a/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index fd8fe1a..a9dedba 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -131,7 +131,6 @@
     }
     else 
     { 
-        self.hasPendingOperation = YES;
         
         if ([self.viewController 
respondsToSelector:@selector(presentViewController:::)]) {
             [self.viewController presentViewController:cameraPicker 
animated:YES completion:nil];        
@@ -139,7 +138,7 @@
             [self.viewController presentModalViewController:cameraPicker 
animated:YES ];
         }              
     }
-    
+    self.hasPendingOperation = YES;
     [cameraPicker release];
 }
 
@@ -150,6 +149,15 @@
     UIPopoverController* pc = (UIPopoverController*)popoverController;
     [pc dismissPopoverAnimated:YES]; 
     pc.delegate = nil;
+    if (self.pickerController && self.pickerController.callbackId && 
self.pickerController.popoverController) {
+        self.pickerController.popoverController = nil;
+        NSString* callbackId = self.pickerController.callbackId;
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus: 
CDVCommandStatus_OK messageAsString: @"no image selected"]; // error callback 
expects string ATM
+        // this "delay hack" is in case the callback contains a JavaScript 
alert. Without this delay or a
+        // setTimeout("alert('fail');", 0) on the JS side, the app will hang 
when the alert is displayed.
+        [self.webView 
performSelector:@selector(stringByEvaluatingJavaScriptFromString:) 
withObject:[result toErrorCallbackString: callbackId] afterDelay:0.5];
+    } 
+    self.hasPendingOperation = NO;
 }
 
 - (void)imagePickerController:(UIImagePickerController*)picker 
didFinishPickingMediaWithInfo:(NSDictionary*)info
@@ -274,6 +282,7 @@
 
 - (void) closePicker:(CDVCameraPicker*)cameraPicker
 {
+    NSLog(@"closePicker is DEPRECATED and will be removed in 2.0!");
     if ([cameraPicker respondsToSelector:@selector(presentingViewController)]) 
{ 
         [[cameraPicker presentingViewController] 
dismissModalViewControllerAnimated:YES];
     } else {
@@ -297,12 +306,7 @@
     } else {
         [[cameraPicker parentViewController] 
dismissModalViewControllerAnimated:YES];
     }        
-    
-    if (cameraPicker.popoverSupported && cameraPicker.popoverController != nil)
-    {
-        cameraPicker.popoverController.delegate = nil;
-        cameraPicker.popoverController = nil;
-    }
+    //popoverControllerDidDismissPopover:(id)popoverController is called if 
popover is cancelled
         
     CDVPluginResult* result = [CDVPluginResult resultWithStatus: 
CDVCommandStatus_OK messageAsString: @"no image selected"]; // error callback 
expects string ATM
     [cameraPicker.webView stringByEvaluatingJavaScriptFromString:[result 
toErrorCallbackString: callbackId]];

Reply via email to