How to get front camera, back camera and audio with AVCaptureDeviceDiscoverySession : <p>Before iOS 10 came out I was using the following code to get the video and audio capture for my video recorder:</p>

<pre><code> for device in AVCaptureDevice.devices()
 {
     if (device as AnyObject).hasMediaType( AVMediaTypeAudio )
     {
         self.audioCapture = device as? AVCaptureDevice
     }
     else if (device as AnyObject).hasMediaType( AVMediaTypeVideo )
     {
         if (device as AnyObject).position == AVCaptureDevicePosition.back
         {
             self.backCameraVideoCapture = device as? AVCaptureDevice
         }
         else
         {
             self.frontCameraVideoCapture = device as? AVCaptureDevice
         }
     }
 }
</code></pre>

<p>When iOS 10 finally came out, I received the following warning when I was running my code. Note that my video recorder was still working smoothly for about 2 weeks.</p>

<blockquote>
  <p>'devices()' was deprecated in iOS 10.0: Use AVCaptureDeviceDiscoverySession instead.</p>
</blockquote>

<p>As I was running my code this morning, my video recorder stopped working. xCode8 does not give me any errors but the previewLayer for the camera capture is completely white. When I then start recording I receive the following error:</p>

<blockquote>
  <p>Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x17554440 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12780)}</p>
</blockquote>

<p>I believe that has something to do with the fact that I am using the deprecated approach <code>AVCaptureDevice.devices()</code>. Hence, I was wondering how to use <code>AVCaptureDeviceDiscoverySession</code> instead?</p>

<p>Thank you for your help in advance!</p>
