Why is ARSession restarted session slowly?

Viewed 42

I am using ARKit for my AR application. I need frequently start and stop ARSession. But when I restart ARSession after stopping it is going to normal state slowly then initial start. It means restarting ARSession is given more time then initial starting. I tried to recreate ARSession instead of restarting, but it is failed always.

Here is my code:

private let session = ARSession()

override func viewDidLoad() {
  super.viewDidLoad()
  setupVM()
  setupARSession()
}

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)
  restartARSession()
}

override func viewWillDisappear(_ animated: Bool) {
  super.viewWillDisappear(animated)
  session.pause()
}

private func startARSession() {
  let configuration = ARWorldTrackingConfiguration()
  configuration.frameSemantics = .sceneDepth

  session.run(configuration)
}

private func restartARSession() {
  if let configuration = session.configuration {
    session.run(configuration, options: .resetSceneReconstruction)
  }
}

How do I restart ARSession faster?

0 Answers
Related