|
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 Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
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.