Black Screen with the text "Move iPad to start"

After getting around some issues we finally got "something" to run.

But we have 2 issues now

  1. getDocumentsDir() is not found on scope.

I guess this function was only shown on the video, but not really implemented globally, now looking through some "eskimo" code I found docDir implementation.

Which doesn't work either in this case.

  1. Because session.start() never runs, all I have is a Black Screen with an animation saying "Move iPad to start".

QUESTION:

A) How can I force this to work?

I'm hoping to get capture the images to later process at a Mac. So I don't think I need the "checkpoint" part of configuration.

Since getDocumentsDir() or docDir are not working,

B) is there anyway to just select whatever folder we can, maybe hardcode it?


Here is my code:

import Foundation
import RealityKit
import SwiftUI
// import Firebase

struct CaptureView: View {

    let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

    var body: some View {

        ZStack {
            // Make the entire background black.
            Color.black.edgesIgnoringSafeArea(.all)
            if #available(iOS 17.0, *) {
                var session = ObjectCaptureSession()
                var configuration = ObjectCaptureSession.Configuration()
                // configuration.checkpointDirectory = getDocumentsDir().appendingPathComponent("Snapshots/")
                // session.start(imagesDirectory: docDir.appendingPathComponent("Images/"), configuration: configuration)

                ObjectCaptureView(session: session)

            } else {

                Text("Unsupported iOS 17 View")

            }

        }
        .environment(\.colorScheme, .dark)
    }
}

Answered by lxps in 755675022

I fixed this by running startSession outside the body. That was causing the issue.

@MainActor func startSession() {
        guard #available(iOS 17.0, *) else { return }
        do {
            let session = ObjectCaptureSession()
            var configuration = ObjectCaptureSession.Configuration()
            configuration.checkpointDirectory = getDocumentsDir().appendingPathComponent("Snapshots/")
            try session.start(imagesDirectory: getDocumentsDir().appendingPathComponent("Images/"), configuration: configuration)
            self.session = session
        } catch {
            sessionError = error
        }
    }

Also added:

.onAppear {
            startSession()
        }

after

.environment(\.colorScheme, .dark)

Here is the final part of the code inside the ZStack

             if let session = session {
                ObjectCaptureView(session: session)
                if case .ready = session.state {
                    Button(action: {
                        session.startDetecting()
                    }) {
                        Text("Continue")
                            .foregroundColor(.white)
                            .padding()
                            .background(Color.blue)
                            .cornerRadius(10)
                    }
                } else if case .detecting = session.state {
                    Button(action: {
                        session.startCapturing()
                    }) {
                        Text("Start Capture")
                            .foregroundColor(.white)
                            .padding()
                            .background(Color.blue)
                            .cornerRadius(10)
                    }
                }
            } else if let error = sessionError {
                Text("Failed to start ObjectCaptureSession: \(error.localizedDescription)")
            } else {
                Text("Initializing...")
            }

As you can see I changed the CreateButton part because it was also not defined in the video. So I went back to the old way of creating buttons.

Hope this helps you move fwd

Accepted Answer

I fixed this by running startSession outside the body. That was causing the issue.

@MainActor func startSession() {
        guard #available(iOS 17.0, *) else { return }
        do {
            let session = ObjectCaptureSession()
            var configuration = ObjectCaptureSession.Configuration()
            configuration.checkpointDirectory = getDocumentsDir().appendingPathComponent("Snapshots/")
            try session.start(imagesDirectory: getDocumentsDir().appendingPathComponent("Images/"), configuration: configuration)
            self.session = session
        } catch {
            sessionError = error
        }
    }

Also added:

.onAppear {
            startSession()
        }

after

.environment(\.colorScheme, .dark)

Here is the final part of the code inside the ZStack

             if let session = session {
                ObjectCaptureView(session: session)
                if case .ready = session.state {
                    Button(action: {
                        session.startDetecting()
                    }) {
                        Text("Continue")
                            .foregroundColor(.white)
                            .padding()
                            .background(Color.blue)
                            .cornerRadius(10)
                    }
                } else if case .detecting = session.state {
                    Button(action: {
                        session.startCapturing()
                    }) {
                        Text("Start Capture")
                            .foregroundColor(.white)
                            .padding()
                            .background(Color.blue)
                            .cornerRadius(10)
                    }
                }
            } else if let error = sessionError {
                Text("Failed to start ObjectCaptureSession: \(error.localizedDescription)")
            } else {
                Text("Initializing...")
            }

As you can see I changed the CreateButton part because it was also not defined in the video. So I went back to the old way of creating buttons.

Hope this helps you move fwd

Black Screen with the text "Move iPad to start"
 
 
Q