AVCaptureSession breaks camera preview in UIImagePickerController

Originator:joemuers.developer
Number:rdar://46489593 Date Originated:05/12/2018
Status:Open Resolved:
Product:iOS Product Version:11, 12
Classification: Reproducible:Always
 
Area:
AVFoundation

Summary:
If you create a new AVCaptureSession, attach it to a camera and start it while UIImagePickerController is currently present on screen, the preview window in UIImagePickerController freezes if you switch between front and rear cameras and the buttons become unresponsive. 

Steps to Reproduce:
Create a simple project with a single "root" ViewController.
Now from inside the root ViewController, create a UIImagePickerController configured like so:
let picker = UIImagePickerController()
picker.sourceType = .camera
picker.mediaTypes = [kUTTypeImage]
picker.cameraDevice = .front
picker.cameraCaptureMode = .photo
and present it on-screen from your root ViewController in the normal way:
self.present(picker, animated: true, completion: nil)

Now, in your root ViewController, create an AVCapture session configured this:
let captureSession = AVCaptureSession()
let device = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera,
                                                    for: AVMediaType.video,
                                                    position: .front)
captureSession.addInput(AVCaptureDeviceInput(device: device))
captureSession.startRunning() // this part is crucial, make sure it's only invoked after the UIImagePickerController is fully on-screen.

(note: make sure your capture session is attached to a view somewhere and is actually showing the camera preview).

Now try flipping between front and rear cameras in the UIImagePickerController.

Expected Results:
Should be able to switch between front and rear camera in the UIImagePickerController as normal. 

Actual Results:
When you try to flip to rear camera, the camera preview freezes on a blurred image and the buttons become unresponsive. 

Version/Build:
Happens on iOS 11 and iOS 12. 
Happens on all iPhone devices (haven't tried iPad).

Configuration:
Nothing specific. 

I've attached a screen recording showing the end result.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!