UIImagePickerControllerCameraDeviceFront only works every other time

ぐ巨炮叔叔 提交于 2019-12-07 12:03:00

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/10967139/uiimagepickercontrollercameradevicefront-only-works-every-other-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!