Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop AVCaptureSession when leaving ViewController

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.

like image 772
moonvader Avatar asked Sep 15 '26 08:09

moonvader


1 Answers

Just have the viewWillDisappear method handle that for you.

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    captureSession?.stopRunning()
}
like image 171
CodeBender Avatar answered Sep 17 '26 21:09

CodeBender