Dropping ARSession on the ARKit framework is quite simple:
class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate { @IBOutlet var arView: ARSCNView! @IBOutlet weak var sessionInfoLabel: UILabel! override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = [.horizontal, .vertical] arView.session.run(configuration) arView.session.delegate = self } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) arView.session.pause() } func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) { guard let planeAnchor = anchor as? ARPlaneAnchor else { return } let plane = Plane(anchor: planeAnchor, in: arView) node.addChildNode(plane) } func sessionInterruptionEnded(_ session: ARSession) { resetSessionTracking() sessionInfoLabel.text = "ARSession interruption has ended" } private func resetSessionTracking() { let config = ARWorldTrackingConfiguration() config.planeDetection = [.vertical, .horizontal] arView.scene.rootNode.enumerateChildNodes { (childNode, _) in childNode.removeFromParentNode() } arView.session.run(config, options: [.removeExistingAnchors, .resetTracking, ]) } }
Hope this helps.
source share