UIImagePickerController displays the wrong camera device every second launch

I have a Root View Controller, from which I proceed to the next scene. This new view controller introduces the UIImagePickerController and selects the front camera when launched inside viewDidLoad:

cameraUI.cameraDevice=UIImagePickerControllerCameraDeviceFront; 

This works, so the front camera is selected and displayed. I take a picture and move on to the next scene. Then I will leave and return to the Root View controller. I move on to the next scene again, which loads the UIImagePickerController again (when debugging, it reappears in viewDidLoad, so this works). Inside viewDidLoad, he again selects the front camera with the code above.

BUT! Now UIImagePickerController shows only the rear camera! If I go back to the root view controller a third time and load the UIImagePickerController again, it now shows the front camera as it should. For the fourth time, he shows the rear camera, etc.

I debugged it and every time it jumps to the code line from above, as expected, so I don’t understand why the rear camera is displayed every second time?

+4
source share
1 answer

I did not release the UIImagePickerController when moving to the next scene. Using:

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

The last line fixed the problem. (I still don't get it, because the view controller that introduced the UIImagePickerController was fully loaded)

+3
source

Source: https://habr.com/ru/post/1399053/


All Articles