AVCaptureVideoPreviewLayer (camera preview) freezes/stuck after moving to background and back

后端 未结 6 662
忘了有多久
忘了有多久 2020-12-15 20:38

Cant figure this one out. Everything works fine when the app is active, and than sometimes when i move the app to the background(pressing the home button) a

6条回答
  •  难免孤独
    2020-12-15 21:17

    I faced this problem too, I fixed mine by adding this to my viewWillAppear and viewWillDissapear. Hope this helps

    var session = AVCaptureSession()
    
    override func viewWillAppear(_ animated: Bool) {
            session.startRunning()
    
        }
    
    override func viewWillDisappear(_ animated: Bool) {
            session.stopRunning()
        }
    

提交回复
热议问题