Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
ARKit camera tracking state can’t show on SwiftUI

I’m trying to show the camera tracking state info on top of device screen, but still get errors for all my efforts. I’m very confused with how ARView works with SwiftUI, for showing AR experience and adding button icons on top of it is simple, but to getting data from session just looks more work need to be done, could someone help me this? Thanks!

Error in ViewModel: ‘description is a get-only property’

Content View

import SwiftUI
import ARKit
import RealityKit

struct ContentView: View {
    @StateObject var vm = ViewModel()
    
    var body: some View {
        ZStack{
            ARViewContainer()
                .edgesIgnoringSafeArea(.all)
                .environmentObject(vm)
            VStack{
                Text(vm.sessionInfoLabel)
                    .font(.title3)
                    .foregroundColor(.red)
                
                Spacer()
                HStack{
                    Button{
                        
                    } label: {
                        Image(systemName: "person.2")
                            .padding()
                            .font(.title)
                    }
                    Spacer()
                    Button{
                        
                    } label: {
                        Image(systemName: "target")
                            .padding()
                            .font(.title)
                    }
                }
                .padding()
                
            }
        }
    }
}

struct ARViewContainer: UIViewRepresentable {
    @EnvironmentObject var vm: ViewModel
    func makeUIView(context: Context) -> ARView {
        return vm.arView
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {
    }
}

ViewModel

import SwiftUI
import ARKit
import RealityKit

class ViewModel: ObservableObject {
    @Published var arView: ARView
    var sessionInfoLabel = ""
    init() {
        arView = ARView.init(frame: .zero)
        let config = ARWorldTrackingConfiguration()
        config.planeDetection = .horizontal
        arView.session.delegate = arView
        arView.session.run(config)
    }
}


extension ARView: ARSessionDelegate {
    public func session(_ session: ARSession, cameraDidChangeTrackingState camera: ARCamera) {
        camera.trackingState.description = ViewModel().sessionInfoLabel
    }
}

extension ARCamera.TrackingState: CustomStringConvertible {
    public var description: String {
        switch self {
        case .normal:
            return "Normal"
        case .notAvailable:
            return "Not Available"
        case .limited(.initializing):
            return "Initializing"
        case .limited(.excessiveMotion):
            return "Excessive Motion"
        case .limited(.insufficientFeatures):
            return "Insufficient Features"
        case .limited(.relocalizing):
            return "Relocalizing"
        case .limited:
            return "Unspecified Reason"
        }
    }
}
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda