|
Hi all, I am currently build an app that uses the camera and when I am on views where there is no camera view object, and I update the view via either a toggle or a button press, the green camera indicator randomly turns on. It happens in multiple views and I have tried serveral options to get it to stop happening. Has anyone experienced this before? Any ideas? This is the camera struct I am using if this helps:
|
|
I found the problem and a solution: .onAppear is and has been bugged for some time and it was being called for views that DID have the camera randomly when I would open other views. SOLUTION: I used .task as a replacement to .onAppear and asyncronously called .startCamera() there. .onDisappear works as intended so I left it as a solution to calling .stopCamera()
And
|
|
The green camera indicator randomly turning on in your SwiftUI app could be due to the AVCaptureSession not being properly stopped when navigating away from views with CameraView. Ensure that you call
And in your
Now, use this
This ensures that the camera session stops properly when the view disappears, preventing the green indicator from randomly appearing. |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.