Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting session `didUpdate` for camera position in ARKit

I'm new to swift, and I'm trying to get the location of the camera in the ARKit example, but it's giving me nil.

I used the solution for this question and set the delegate to self, but it's still not giving me the camera transform.

What am I doing wrong?

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet var sceneView: ARSCNView!

    override func viewDidLoad() {
        super.viewDidLoad()
        sceneView.delegate = self
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let configuration = ARWorldTrackingSessionConfiguration()
        sceneView.session.run(configuration)
    }

    func session(_ session: ARSession, didUpdate frame: ARFrame) {
        print("Hello")     // DOES NOT RUN HERE
        let currentTransform = frame.camera.transform
    }
}
like image 556
dmr07 Avatar asked Aug 04 '17 23:08

dmr07


1 Answers

Simple fix, first your class definition:

class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate

Then you'll need to set yourself as the delegate like so:

sceneView.session.delegate = self

And then everything's going to work just right.

like image 101
Shriphani Palakodety Avatar answered Nov 02 '22 04:11

Shriphani Palakodety