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

后端 未结 6 655
忘了有多久
忘了有多久 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:15

    Roi,

    I think your problem is that you are doing all the session setup and such in the viewWillAppear. Lets say that the captureSession, and the previewLayer were both alloc'd and working correctly. Now, you put app into the background and bring back.

    You will immediately try to create a new captureSession, and a new previewLayer. I suspect that the old ones and the new ones are getting tangled up.

    In the Apple AVCam example they do the setup in the viewDidLoad. That way it is only done once.

    You should move all your setup stuff to a method and then call the method from the viewDidLoad.

    bill

提交回复
热议问题