5

I'm trying to run ARWorldTracking Session and ARFaceTracking Session at the same time on iPhoneX, but the first running session stopped after the later session begun to run.

Is is impossible to implement? This is my ViewController.swift code.

import UIKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate, 
ARSessionDelegate {
    @IBOutlet weak var frontView: ARSCNView!
    @IBOutlet weak var backView: ARSCNView!
    override func viewDidLoad() {
       super.viewDidLoad()
       startTracking()
    }

   func startTracking() {
       let backConfiguration = ARWorldTrackingConfiguration()
       backView.session.run(backConfiguration)

       let frontConfiguration = ARFaceTrackingConfiguration()
       frontConfiguration.isLightEstimationEnabled = true      
       frontView.session.run(frontConfiguration)
  }
}
Scoff
  • 105
  • 9

2 Answers2

2

Nope.

ARKit relies upon the AVCapture system, and that doesn’t support using more than one capture device (camera) at a time. If you start a capture session using the front camera while another session is using the back camera, the existing session stops.

rickster
  • 124,678
  • 26
  • 272
  • 326
  • I tried to run AVCaptureSession and ARSession at the same time before I post this question, and xcode suggested session error. That's what you mean! – Scoff Dec 11 '17 at 05:58
-1

ARSession is a singleton, so changing the configuration is going to change the state of the shared session. from the docs:

ARSession A shared object that manages the device camera and motion processing needed for augmented reality experiences.

Josh Homann
  • 15,933
  • 3
  • 30
  • 33
  • Thank for your quick reply! – Scoff Dec 06 '17 at 15:19
  • 1
    An object can be shared across multiple use sites in some domain without being a singleton. `ARSession` has an initializer that returns distinct instances, so it’s not a singleton. – rickster Dec 08 '17 at 05:51