3

I have ViewController with AVCaptureSession. I can start and stop AVCaptureSession easily :

var captureSession: AVCaptureSession?
captureSession = AVCaptureSession()

//start
captureSession?.startRunning() 

//stop
captureSession?.stopRunning() 

A want to know how can I stop AVCaptureSession when user opens another ViewController.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
moonvader
  • 19,761
  • 18
  • 67
  • 116

1 Answers1

1

Just have the viewWillDisappear method handle that for you.

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    captureSession?.stopRunning()
}
CodeBender
  • 35,668
  • 12
  • 125
  • 132