Opening front camera on Vision Pro

Hey!

I'm trying to open the front camera on my demo app, and from what I read on the Apple docs and forums if you have configured your Persona you will get that image.

But I'm having some issues with it, this is my code:

struct ContentView: View {
    @Environment(\.presentationMode) var presentationMode

    var body: some View {
        ZStack {
                    VStack {
                        Image("logo")
                            .resizable()
                            .frame(width: 337, height: 211)
                            .accessibilityHidden(true)
                        Text("My first Vision Pro app.")
                            .multilineTextAlignment(.center)
                            .font(.headline)
                            .frame(width: 340)
                            .padding(.bottom, 10)
                        Button {
                          // Add camera functionality here
                        } label: {
                          Text("Open Camera")
                          .frame(maxWidth: .infinity)
                        }
                        .onAppear {
                          requestCameraAccess()
                        }
                        .onTapGesture {
                          // Check if camera permission is granted
                          if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
                            openFrontCamera()
                          } else {
                            requestCameraAccess()
                          }
                        }
                        
                }
            
            
        }
            
        }
    
    func requestCameraAccess() {
        AVCaptureDevice.requestAccess(for: .video) { authorized in
            DispatchQueue.main.async {
              if authorized {
                // Permission granted, open camera if needed
                openFrontCamera()
              } else {
                // Handle permission denied case (optional)
              }
            }
          }
    }

    func openFrontCamera() {
        
    }


}```

On the openFrontCamera() function I tried using .devices() .default() and other methods like you would use for other Apple devices but this doesn't work with Vision Pro and I can't find anything that tells me how to open it.

Has anyone been able to work this out?

Replies

Capturing a live feed off the cameras is not available in visionOS for privacy reasons.

Post not yet marked as solved Up vote reply of Dude Down vote reply of Dude
  • @Dude Thank you for the info. I just read the doc and I get why Apple doesn't let developers use the cameras and sensors for now. But do you know if there is some way of interacting with the Digital Persona on a custom app?

    From what I gathered, you can only use the persona on videoconference apps like Zoom, Teams, or Facetime, I was wondering if you could do that with a custom app.

  • Not sure about manipulating the personas but including them in your app probably involves implementing something in the group activities framework.

Add a Comment