Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera freezes if didFinishPickingMediaWithInfo is defined

I'm trying to do a basic picture taking with iPhone. I used the following code to show the camera:

 - (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
                                       usingDelegate: (id <UIImagePickerControllerDelegate,
                                                       UINavigationControllerDelegate>) delegate {

        if (([UIImagePickerController isSourceTypeAvailable:
              UIImagePickerControllerSourceTypeCamera] == NO)
            || (delegate == nil)
            || (controller == nil))
            return NO;


        UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

        // Displays a control that allows the user to choose picture or
        // movie capture, if both are available:
        cameraUI.mediaTypes =
        [UIImagePickerController availableMediaTypesForSourceType:
         UIImagePickerControllerSourceTypeCamera];

        // Hides the controls for moving & scaling pictures, or for
        // trimming movies. To instead show the controls, use YES.
        cameraUI.allowsEditing = NO;

        cameraUI.delegate = delegate;

    [controller presentModalViewController: cameraUI animated: YES];
    return YES;
}

This works fine, but then if I define the handling function:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

}

The imagePicker control freezes after pressing the Use button. It doesn't crash, doesn't throw any exception, the code is doing something, but on the screen I just see the frozen imagePicker control. Even if the handler is empty the control freezes. If I remove the handler, the camera disappears normally and shows the view from where the camera was activated... Did I miss something essential here?

UPDATE: I tried assigning the image to an UIImageView, the code executes, exits the function and that's it, the camera remains on the screen:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    UIImage* original =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [[self imgWLItemImage] setImage:[UIImage imageWithCGImage:original.CGImage scale:0.25 orientation:original.imageOrientation]];
}
like image 407
taralex Avatar asked Dec 21 '12 02:12

taralex


1 Answers

Try this & check:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   [picker dismissModalViewControllerAnimated:YES];
    UIImage* original =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [[self imgWLItemImage] setImage:[UIImage imageWithCGImage:original.CGImage scale:0.25 orientation:original.imageOrientation]];
}
like image 194
Vishal Avatar answered Oct 11 '22 16:10

Vishal