'Import and display .usdz file in swift

I try to import some .usdz files into the app and display the 3D model using SceneView. When I display some model which already in my Xcode folder, it works. But when run the app on my phone and try to import files from my Phone, print(fileName) still can get the right file name but nothing displayed in the SceneView... Anyone can help?

@State var fileName = ""
@State var openFile = false
@State var model = Model(id: 0, modelName: "")

var body: some View {
    VStack{
        VStack {
            Text(fileName)
                .fontWeight(.bold)

            Button {
                openFile.toggle()
            } label: {
                Text("Come On")
            }
        }
        .fileImporter(isPresented: $openFile, allowedContentTypes: [.usdz]) {  result in
            switch result {
            case .success(let url):

                _ = url.startAccessingSecurityScopedResource()
                print(url)
                self.fileName = url.lastPathComponent
                print(fileName)
                model.modelName = fileName

            case.failure(let error):
                print(error)
            }
        }
        SceneView(scene: SCNScene(named: model.modelName) , options: [.autoenablesDefaultLighting,.allowsCameraControl])
            .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source