iOS 7 UIImagePickerController has black preview

During one of my recent projects I had this same (or similar) issue, namely the Camera preview showing a black screen when using UIImagePickerController on iOS7 (iPad).

What I discovered is that GCD in itself is not the problem. The problem occurs when you try to use anything at all from the UIKit framework in a thread other than the main thread (as part of an NSOperation).

First of all, let me start by saying that it is clear to me that you shouldn’t do this to begin with. In my specific case, however, I had no choice. Since I think that there’s a good chance that other people might be experiencing the same weird UIImagePickerController camera behaviour with the same cause, I made up some very simple example code explaining what’s going on.

You can find it here: https://github.com/idamediafoundry/CameraTest

The ViewController shows 2 simple buttons. One calls UIImagePickerController, showing the camera, the other starts some GCD operations doing a simple task. If you just open the camera, everything works fine. If you first start the operations and then open the camera, the black preview issue occurs.

Again, you shouldn’t call UIKit in anything but the main thread. But I don’t think it’s normal that breaking this rule causes the camera to malfunction when opening it later in the main thread as part of a completely different flow, right?

Hope this helps.

Leave a Comment