Xcode ARKit 项目:致命错误:在展开可选值时意外发现 nil

问题描述 投票:0回答:0

我注意到,当我尝试使用 Xcode 在 IOS 上创建 AR 项目时,即使我使用默认设置和默认项目 - 我也会收到这种“Fatal Error”:

//
//  ViewController.swift
//  test
//
//

import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet var sceneView: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the view's delegate
        sceneView.delegate = self
        
        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true
        
        // Create a new scene
        let scene = SCNScene(named: "art.scnassets/ship.scn")!
        
        // Set the scene to the view
        sceneView.scene = scene
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // Create a session configuration
        let configuration = ARWorldTrackingConfiguration()

        // Run the view's session
        sceneView.session.run(configuration)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        // Pause the view's session
        sceneView.session.pause()
    }

    // MARK: - ARSCNViewDelegate
    
/*
    // Override to create and configure nodes for anchors added to the view's session.
    func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
        let node = SCNNode()
     
        return node
    }
*/
    
    func session(_ session: ARSession, didFailWithError error: Error) {
        // Present an error message to the user
        
    }
    
    func sessionWasInterrupted(_ session: ARSession) {
        // Inform the user that the session has been interrupted, for example, by presenting an overlay
        
    }
    
    func sessionInterruptionEnded(_ session: ARSession) {
        // Reset tracking and/or remove existing anchors if consistent tracking is required
        
    }
}

我一启动应用程序,我就在调试中遇到这个错误:

2023-04-16 02:12:05.471666+0300 test[13308:8472291] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
2023-04-16 02:12:05.471706+0300 test[13308:8472291] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
2023-04-16 02:12:05.475942+0300 test[13308:8472291] Metal GPU Frame Capture Enabled
2023-04-16 02:12:05.476043+0300 test[13308:8472291] Metal API Validation Enabled
test/ViewController.swift:26: Fatal error: Unexpectedly found nil while unwrapping an Optional value
2023-04-16 02:12:05.549337+0300 test[13308:8472291] test/ViewController.swift:26: Fatal error: Unexpectedly found nil while unwrapping an Optional value
(lldb) 

但我 100% 确定该文件位于文件夹 art.scnassets 中并且路径名是正确的。

ios swift xcode arkit
© www.soinside.com 2019 - 2024. All rights reserved.