我有两个ViewControllers,一个带有ARSCNView,另一个带有一些数据。从第二个视图控制器切换回第一个视图控制器时,ARSession无法正常工作。
我已经尝试保存世界地图,并在单击“后退按钮”从一个视图到另一个视图之后将其还原。
我还尝试了在堆栈溢出时已经在此处提供的Session的所有重置内容
我确实覆盖了这些方法:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
print("view did disappear")
sceneView.session.getCurrentWorldMap { (worldMap, error) in
guard let worldMap = worldMap else {
print("Error getting current world map.")
return
}
do {
try self.archive(worldMap: worldMap)
DispatchQueue.main.async {
print("World map is saved.")
}
} catch {
fatalError("Error saving world map: \(error.localizedDescription)")
}
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let worldMapData = retrieveWorldMapData(from: worldMapURL)
var worldMap: ARWorldMap? = nil
if worldMapData != nil {
worldMap = unarchive(worldMapData: worldMapData!)
}
resetTrackingConfiguration(with: worldMap)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// self.mode = .showFeaturePoints
}
func resetTrackingConfiguration(with worldMap: ARWorldMap? = nil) {
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.horizontal]
let options: ARSession.RunOptions = [.resetTracking, .removeExistingAnchors]
if let worldMap = worldMap {
configuration.initialWorldMap = worldMap
print("Found saved world map.")
} else {
print("Move camera around to map your surrounding space.")
}
sceneView.debugOptions = [.showFeaturePoints, .showWireframe]
sceneView.session.run(configuration, options: options)
}
我只希望我的ARSession在按下UINavigation的后退按钮后能够正常工作