4

I have bug with UIImagePickerController which source type is camera. Sometimes after controller appeared, shutter is not opens up and I can't to see a camera video signal, but photo taken is correct. enter image description here

May be I doing something wrong? Code:

    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){

            UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
            cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
            cameraUI.allowsEditing = NO;
            cameraUI.showsCameraControls = NO;
            cameraUI.delegate = self;

            NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
            UIView *controlsView = [nibObjects objectAtIndex:0];

            CGRect overlayViewFrame = cameraUI.cameraOverlayView.frame;
            CGRect controlsFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame) - 54.0,
                                         CGRectGetWidth(overlayViewFrame), 54.0);

            controlsView.frame = controlsFrame;
            [cameraUI.cameraOverlayView addSubview:controlsView];

            [self presentModalViewController: cameraUI animated: YES];            
    }
jscs
  • 63,694
  • 13
  • 151
  • 195
Arsynth
  • 761
  • 9
  • 22
  • are you doing something very processor intensive at the point where you show the picker? – Mike K Jan 25 '12 at 07:00
  • no, I don't. Shutter just hang up at infinitive time, but all controls responds normally – Arsynth Jan 25 '12 at 08:01
  • One clarification! Recently I noticed, what bug reproduces after going from task bar to application: First step - turn application to task bar Second - turn on application from task bar Third - make camera initialization – Arsynth Jan 27 '12 at 08:18
  • I fixed the bug. I forgot to release a cameraUI at end – Arsynth Feb 01 '12 at 05:25

3 Answers3

1

The same was happening to me after locking/unlocking the app, it looks like the shutter opens on viewDidAppear.

So, I subscribed my parent view controller to UIApplicationDidBecomeActiveNotification and re-execute manually the viewWillAppear and viewDidAppear methods of the controller containing the UIImagePickerController

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(applicationBecomeActive)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:nil];

.
. 
.

- (void)applicationBecomeActive {
    if (imagePicker_)
        [imagePicker_ openShutter];
}

And then on the controller containing the UIImagePickerController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [imagePickerController_ viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [imagePickerController_ viewDidAppear:animated];
    imagePickerController_.cameraFlashMode = cameraFlashMode_;
    imagePickerController_.cameraDevice = cameraDevice_;
}
- (void)openShutter {
    [imagePickerController_ viewWillAppear:YES];
    [imagePickerController_ viewDidAppear:YES];
}

PS: If you try this, don't forget to remove the observer

[[NSNotificationCenter defaultCenter] removeObserver:self];

Hope this helps

Juan de la Torre
  • 1,297
  • 9
  • 19
1

If you are presenting the UIImagePickerController not modally (the recommended way), then you can either call the viewDidAppear and willAppear manually, or add the UIImagePickerController as child view controller from where you are presenting .

[thePresentingViewCotnroller addChildViewController:imagePickerController];

after this you can add the view from the imagePickerController as a subview, this will make the view life cycle methods (viewWillAppear, didAppear and disappear) called automatically.

Basheer_CAD
  • 4,908
  • 24
  • 36
-1

Try adding auto release when you initialize the UIImagePickerController:

UIImagePickerController *pickerController = [[[UIImagePickerController alloc] init] autorelease];
Nathan
  • 1,135
  • 2
  • 12
  • 27