JayAr
JayAr

Reputation: 441

UIImagePickerController displays wrong camera device every second startup

I have a Root View Controller from which I go to the next scene. This new View Controller presents a UIImagePickerController and chooses the front camera on startup inside viewDidLoad:

cameraUI.cameraDevice=UIImagePickerControllerCameraDeviceFront;

This works, so the frontcamera is chosen and gets displayed. I take a picture, and go to the next scene. Then I quit and go back to the Root View Controller. I go to the next scene again which again loads up a UIImagePickerController (when debugging it goes into viewDidLoad again, so this works). Inside viewDidLoad it again chooses the front camera with the code from above.

BUT! The UIImagePickerController only shows the rear camera, now! If I go back to the root view controller a third time and load the UIImagePickerController again, now it shows the front camera like it should. The fourth time it shows the back camera and so on.

I debugged it and everytime it jumps to the codeline from above like expected, so I don`t get why the rear camera is displayed every second time?

Upvotes: 4

Views: 1243

Answers (1)

JayAr
JayAr

Reputation: 441

I didn´t release the UIImagePickerController object when moving to the next scene Using:

    [cameraUI dismissModalViewControllerAnimated:NO];
    [cameraUI.view removeFromSuperview];
    [cameraUI release];

The last line fixed the issue. (I still don´t really get this, because the View Controller that presented the UIImagePickerController was completely loaded again)

Upvotes: 3

Related Questions