title: Camera Access Request fails - but ONLY the first time the camera is accessed Swift 3
body: <p>This iOS app uses the camera for an image to be placed in the detail view of a master detail app. When the app is installed and the take photo action is requested for the first time, the app crashes. As seen in the code, access is requested and the user is presented with an alert requesting access. Once granted the completion handler reports success and the app crashes. If I restart the app (without reinstalling it), the camera performs as expected and continues to do so. Removing the app from the iPhone and reinstalling always produces exactly the same result.</p>
  
  <p>The console output:
  AVAuthorizationStatus is NotDetermined.<br>
  The user granted permission.<br>
  libc++abi.dylib: terminating with uncaught exception of type NSException</p>
  
  <p>Any help would be appreciated. iOS 10, Xcode 8, Swift 3</p>
  
  <p>Edit: It crashes in the AVCaptureRequest. If I comment out the AVCaptureRequest the app does not crash (of course with no photo).</p>
  
  <pre><code>@IBAction func takeDrugPhoto(_ sender: UIButton) {
  
  
      if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
  
          let authStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
  
          switch authStatus {
  
          case AVAuthorizationStatus.authorized:
              print("AVAuthorizationStatus is Authorized")
  </code></pre>
  
  <p>.....bunch of code here......</p>
  
  <pre><code>        case AVAuthorizationStatus.denied:
              print("AVAuthorizationStatus is Denied")
  </code></pre>
  
  <p>.....some code here .....</p>
  
  <pre><code>        case AVAuthorizationStatus.notDetermined:
              print("AVAuthorizationStatus is NotDetermined")
  
  
              AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (success) in
  
                  if success {
                      print("The user granted permission")
  
                  } else {
                      print("put up an alert telling the user the camera is not available")
  
                      DispatchQueue.main.async(execute: { () -&gt; Void in
                          let ac = UIAlertController(title: "Camera Error", message: "For some reason, the camera in this device is not accepting your authorization. Check with your device supplier.", preferredStyle: .alert)
                          ac.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
                          self.present(ac, animated: true, completion: nil)
                      })//back on main queue block
                  }//if success
  
              })//requestAccessForMediaType block
  
  
          }//switch
  
      } else {//if device has a camera
  
          let ac = UIAlertController(title: "Source not available.", message: "The camera is not available.", preferredStyle: .alert)
          ac.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
          present(ac, animated: true, completion: nil)
  
      }//if camera is no else
  
  }//takeDrugPhoto
  </code></pre>
  
  <p>From the trace:</p>