Use an ARSCNView on devices that don't support ARKit

1.3k views Asked by At

Is it possible to use an ARSCNView, configure it with an ARWorldTrackingConfiguration for device that support it, and configure it another way for devices that don't support it (with A8 chip and lower) and still have the video render in the background?

if ARWorldTrackingConfiguration.isSupported{
    let config=ARWorldTrackingConfiguration()
    config.planeDetection = .horizontal
    sceneView.session.run(config)
}else if AROrientationTrackingConfiguration.isSupported{
    let config=AROrientationTrackingConfiguration()
    sceneView.session.run(config)
}else{
    print("not supported")
    //what here?  <<<
}
2

There are 2 answers

5
rickster On BEST ANSWER

You need a running ARSession to drive the camera feed to an ARSCNView, to run an ARSession you need a supported ARConfiguration, and all configurations require A9.

However, if your below-A9 fallback plan is to have a SceneKit view that doesn't get any of ARKit's motion tracking... you don't need ARKit. Just use a regular SceneKit view (SCNView). To make the camera feed show up behind your SceneKit content, find the AVCaptureDevice for the camera you want, and pass that to the background.contents of the scene in your view.

(Using a capture device as a SceneKit background is new in iOS 11. It doesn't appear to be in the docs (yet?), but it's described in the WWDC17 SceneKit session.)


By the way, there aren't any devices that support orientation tracking but don't support world tracking, so the multiple-branch if statement in your question is sort of overkill.

0
9to5ios On

Below code resolve this issue, it might be broken code

let device = sceneView.device!
let maskGeometry = ARSCNFaceGeometry(device: device)!
mask = Mask(geometry: maskGeometry, maskType: maskType)

replace with

    let device = MTLCreateSystemDefaultDevice()
    let maskGeometry = ARSCNFaceGeometry(device: device!)!
    mask = Mask(geometry: maskGeometry)