Use ARKit with NavigationView

I want to use ARKit with NavigationView.

However, when the AR is displayed using it, and it returns to Navigation View and redisplays, the app crashes.

Please tell me how to fix it or an alternative.

Accepted Reply

This thread has been deleted

No error will occur, but the app will stop.

Procedure:

1.Launch app

2.Show AR View

3.Return to the first screen

4.Open AR View again

5.App stops


Xcode: 11.2.1 (11B500)

iOS: iPadOS13.3 beta3 (Japanese)

Device: iPad Pro (11-inch, 2018)


I tried two types of code.

(oneView is an AR view)

Code:

import SwiftUI
import RealityKit

struct ContentView: View {
   
    var body: some View {
        NavigationView {
            List {
            VStack {
                NavigationLink(destination: oneView()) {
                    Text("Watch")
                }
                }.navigationBarTitle("AR")
    }
    }.navigationViewStyle(StackNavigationViewStyle())
}
}

struct ARViewContainer: UIViewRepresentable {
   
    func makeUIView(context: Context) -> ARView {
       
        let arView = ARView(frame: .zero)
       
        // Load the "Box" scene from the "Experience" Reality File
        let boxAnchor = try! Experience.loadBox()
       
        // Add the box anchor to the scene
        arView.scene.anchors.append(boxAnchor)
       
        return arView
       
    }
   
    func updateUIView(_ uiView: ARView, context: Context) {}
   
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif


Code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
            NavigationLink(destination: oneView()) {
                Text("Show Next")
            }
            }
        }
    }
}

Replies

>the app crashes. Please tell me how to fix


Burden is on you to provide more details, including errors and a description of what's going on - what you did, what occured, how those differ.


Include code snippets that the errors point to, and the first couple dozen lines of any crash reports. Also the version Xcode you're using and what iOS & device you're testing on.


SeeFor Best Results - Read the Label