Reputation: 130193
In my app I'm attempting to use the front camera by default in a UIImagePicker
. I know, seems simple enough...
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
Now, the first time I launch my picker everything works fine and the front camera is initialized, but when the picker is dismissed, and presented again the back camera is used. From there on out if I continuously open and close the picker the camera used will be: front, back, front, back, front, back...
I've stripped this code down to the bare basics of the picker attempting to isolate the problem and it persists. Has anyone run into this issue before? Any pointers or direction would be greatly appreciated!
EDIT: Problem solved! I was calling imagePicker = [[UIImagePickerController alloc] init];
in viewDidLoad
instead of viewDidAppear
!
Upvotes: 3
Views: 1633
Reputation: 35616
The problem must be at how you try to initialize/present/dismiss your controller.
So, why this back and forth between cameras?
It seems that the underlying AVCaptureSession
for some reason kept running after the dismiss of the controller. So the next time you presented it, it tried to add the input but it was bussy, so went to the next available (the rear camera), interrupted itself (thus freeing the previous one) and so on.
Upvotes: 5