Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 10 UIImagePickerController black screen

I'm facing a strange problem....
On devices running iOS 10 camera preview shows black screen.
But in older version it works fine.
I'm using UIImagePickerController with

self.sourceType = UIImagePickerControllerSourceTypeCamera;

My info.plist file:

enter image description here

enter image description here

Example project: https://github.com/arturdev/cameraTest

like image 845
arturdev Avatar asked Dec 01 '25 06:12

arturdev


2 Answers

I solved this with different approach.

Don't make subclass of UIImagePickerController because Apple does not support subclass of UIImagePickerController.

Important

The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

Here is alternate solution:

Add this code in UIViewController

self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePickerController.showsCameraControls = NO;
self.imagePickerController.delegate = self;

[self.view addSubview:self.imagePickerController.view];
[self addChildViewController:self.imagePickerController];
[self.imagePickerController didMoveToParentViewController:self];

Working Fine in all iOS version and devices. :):)

like image 164
Ankit Gupta Avatar answered Dec 03 '25 21:12

Ankit Gupta


Use UIImagePickerController() instead of any other initializer.

I am facing the same problem, and it is caused by calling the wrong initializer.

like image 33
Sivda Avatar answered Dec 03 '25 21:12

Sivda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!