1

I am working on a 3D Scanning app and I created the test extension below in order to check if my user's device has a TrueDepth camera. Currently I have a problem in my app where I have to keep changing the list of compatible devices from Apple's Docs and keep updating the reflection switch-cases from here.

static let hasTrueDepthCamera: Bool = {
    let authContext = LAContext()
    let _ = authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
    return authContext.biometryType == LABiometryType.faceID;
}()

I was wondering if the extension will work even if the user's FaceId is not setup in their settings, or will it return false? Unfortunately, I am not able to test it on my phone because it will remove all the cards from my account wallet.

Saamer
  • 4,687
  • 1
  • 13
  • 55

2 Answers2

1

One possible way to detect if the device has TrueDepth Camera or not, is to check if the device supports face tracking or not, using ARkit's ARFaceTrackingConfiguration. You can use following code to detect if the device support face tracking.

guard ARFaceTrackingConfiguration.isSupported else {
  fatalError("Error: This device model does not support face tracking")
}
Sajjad Ali
  • 15
  • 5
  • Yes; I think this is the most confident way to make sure True depth is available. This also checks that device has a proper chip to run true depth features – Manu Feb 09 '23 at 19:00
0

You should be able to achieve this directly with AVFoundation (which is most likely how frameworks like ARKit go about it).

Here's a Swift sample code:

let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTrueDepthCamera], mediaType: .depthData, position: .front)
guard let depthDevice = discoverySession.devices.first else {
    print("Your device does not have a TrueDepth front camera")
    return
}
Mr_Pouet
  • 4,061
  • 8
  • 36
  • 47