title: App crashes with: startRunning may not be called between calls to beginConfiguration and commitConfiguration?
body: <p>I am working on an app that is using a pod named WeScan (see their <a href="https://github.com/WeTransfer/WeScan" rel="nofollow noreferrer">github</a>).</p>
  
  <p>After setting everything up and adding the correct items to my info.plist file my app keeps crashing. </p>
  
  <p>The error is: </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration' "  </p>
  </blockquote>
  
  <p>Here is the code from the pod that I think is causing the problem:</p>
  
  <pre><code>init?(videoPreviewLayer: AVCaptureVideoPreviewLayer) {
  self.videoPreviewLayer = videoPreviewLayer
  super.init()
  
  captureSession.beginConfiguration()
  captureSession.sessionPreset = AVCaptureSession.Preset.photo
  
  photoOutput.isHighResolutionCaptureEnabled = true
  
  let videoOutput = AVCaptureVideoDataOutput()
  videoOutput.alwaysDiscardsLateVideoFrames = true
  
  guard let inputDevice = AVCaptureDevice.default(for: AVMediaType.video),
      let deviceInput = try? AVCaptureDeviceInput(device: inputDevice),
      captureSession.canAddInput(deviceInput),
      captureSession.canAddOutput(photoOutput),
      captureSession.canAddOutput(videoOutput) else {
          let error = ImageScannerControllerError.inputDevice
          delegate?.captureSessionManager(self, didFailWithError: error)
          return
  }
  
  captureSession.addInput(deviceInput)
  captureSession.addOutput(photoOutput)
  captureSession.addOutput(videoOutput)
  
  videoPreviewLayer.session = captureSession
  videoPreviewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
  
  videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "video_ouput_queue"))
  
  captureSession.commitConfiguration()
  }
  
  // MARK: Capture Session Life Cycle
  
  /// Starts the camera and detecting quadrilaterals.
  internal func start() {
      let authorizationStatus = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
  
      switch authorizationStatus {
      case .authorized:
          self.captureSession.startRunning()
          isDetecting = true
      case .notDetermined:
          AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { (_) in
             DispatchQueue.main.async { [weak self] in
                  self?.start()
              }
          })
      default:
          let error = ImageScannerControllerError.authorization
          delegate?.captureSessionManager(self, didFailWithError: error)
      }
  }
  
  internal func stop() {
      captureSession.stopRunning()
  }
  
  internal func capturePhoto() {
      let photoSettings = AVCapturePhotoSettings()
      photoSettings.isHighResolutionPhotoEnabled = true
      photoSettings.isAutoStillImageStabilizationEnabled = true
  
      if let photoOutputConnection = self.photoOutput.connection(with: .video) {
          photoOutputConnection.videoOrientation = AVCaptureVideoOrientation(deviceOrientation: UIDevice.current.orientation) ?? AVCaptureVideoOrientation.portrait
      }
  </code></pre>