Not getting camera frame using enterprise API in Vision Pro

I don't get cameraFrame from cameraFrameUpdates in vision pro app, why it's no getting , where I am doing wrong in code please guide me.

for await cameraFrame in cameraFrameUpdates { print("cameraFrame:: (cameraFrame)") }



var body: some View {

        VStack {

            image

                .resizable()

                .scaledToFit()

            if(self.finalImage != nil){

                self.finalImage!

                    .resizable()

                    .scaledToFit()

            }else{

                image

                    .resizable()

                    .scaledToFit()

            }

        }

        .task {

            if #available(visionOS 2.0, *) {

                guard CameraFrameProvider.isSupported else {

                    print("CameraFrameProvider not supported.")

                    return

                }

                

                

                let formats = CameraVideoFormat.supportedVideoFormats(for: .main, cameraPositions: [CameraFrameProvider.CameraPosition.left])

                

                let cameraFrameProvider = CameraFrameProvider()

                

                do {

                    try await arkitSession.run([cameraFrameProvider])

                } catch {

                    guard let sessionError = error as? ARKitSession.Error else {

                        preconditionFailure("ARKitSession.run() returned a non-session error: \(error)")

                        print("ARKitSession.run() returned a non-session error: \(error)")

                    }

                }



                guard let cameraFrameUpdates = cameraFrameProvider.cameraFrameUpdates(for: formats[0]) else {

                    preconditionFailure("Failed to get an async sequence for the first format.")

                    print("Failed to get an async sequence for the first format.")

                }

                

                print("cameraFrameUpdates:: \(cameraFrameUpdates)")

                

                 for await cameraFrame in cameraFrameUpdates {

                    

                    print("cameraFrame:: \(cameraFrame)")

                    

                    print("Camera Frame ::: LEFT :: \(cameraFrame.sample(for: .left))")

                    

                    guard let leftSample = cameraFrame.sample(for: .left) else {

                        print("CameraFrameProviderSample - Nil camera frame left sample")

                        print("CameraFrameProviderSample - Nil camera frame left sample")

                        continue

                    }



                    self.pixelBuffer = leftSample.pixelBuffer

                    print(" ======== PIXEL BUFFER  ::: \(self.pixelBuffer) ========")

                    self.finalImage = self.setImage()

                }

            } else {

                // Fallback on earlier versions

            }

        }

    }



Hi @Sandip_Aura

I'm happy to help. The code looks correct. It appears you are starting an ARKit session using the appropriate provider. I have a few questions:

  • ARKit only runs in an immersive space. Is this view in an immersive space?
  • Can you share the console output? What's the last print statement logged? Are there any errors?
  • Is the app executing on a device running visionOS 2.0? Consider adding a print statement just under "// Fallback on earlier versions" to make sure the code is being executed.

@Sandip_Aura

I used your source to create a new project with the appropriate entitlement, license and info plist entry and get frames. Here are a few things to check:

  • Ensure your info.plist has an entry for NSEnterpriseMCAMUsageDescription to provide a usage description that explains how your app uses the camera frames.
  • Ensure your license file is included in your Xcode project and is a member of your app's run target.
  • You mentioned you have an entry in your entitlements file for com.apple.developer.arkit.main-camera-access.allow. That's correct. I'm calling it out for those who come after you. Ensure this entitlements file is referenced via "Code Signing Entitlements" in your project's settings.

For more information refer to Building spatial experiences for business apps with enterprise APIs for visionOS.

@Sandip_Aura I'm running into the same issue with spatial barcode scanning. Have you come across any solutions for this?

Not getting camera frame using enterprise API in Vision Pro
 
 
Q