Check if iOS device has LiDAR in Swift

Viewed 1724

is there a way in Swift to check if the device has a LiDAR sensor? Unfortunately I've didn't find anything in the official Apple documentary nor with internet search.

My current workaround is to determine the device type like described in this post: How to determine the current iPhone/device model?

Thanks

2 Answers

The Accepted answer is fine and here is another solution :

you can check for the availability of depth data from LiDAR, we need to check whether our device supports this sensor and enable its flag ‘.sceneDepth’ in ARConfiguration.

Use This Func

 func setupARConfiguration() -> ARConfiguration{
    let configuration = ARWorldTrackingConfiguration()
    
    // add specific configurations
    if ARWorldTrackingConfiguration.supportsFrameSemantics(.sceneDepth) {
        configuration.frameSemantics = .sceneDepth
    }else {
        print("Device is not support lidar sensor")

    }
    
    return configuration
}

from Apple Docs :

Call this function before attempting to enable a frame semantic on your app's configuration. For example, if you call supportsFrameSemantic(.sceneDepth) on ARWorldTrackingConfiguration, the function returns true on devices that support the LiDAR scanner's depth buffer.

Ref : https://developer.apple.com/documentation/arkit/arconfiguration/3089122-supportsframesemantics

Related