Check if iOS device has LiDAR in Swift
Asked Answered
R

3

6

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

Royceroyd answered 26/2, 2021 at 9:34 Comment(1)
Dipika Kansara posted an Answer saying "Apple Documentation of LIDAR Scanning"Salpingotomy
I
10

Use this code:-

import ARKit

let supportLiDAR = ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh)
guard supportLiDAR else {
    print("LiDAR isn't supported here")
    return
}

Scene reconstruction requires a device with a LiDAR Scanner, such as the fourth-generation iPad Pro.

reference:- https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration/3521377-supportsscenereconstruction

Innermost answered 26/2, 2021 at 10:58 Comment(0)
I
2

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

Ineradicable answered 11/9, 2021 at 11:20 Comment(0)
A
1

You could check if AVCaptureDevice is able to detect a device with type builtInLiDARDepthCamera using default(_:for:position:) (adjust the media type / position as needed):

if let device = AVCaptureDevice.default(.builtInLiDARDepthCamera, for: .video, position: .back) { 
    // LiDAR is available
}

Alternatively you can use an AVCaptureDevice.DiscoverySession to determine what camera devices are available on the device.

Akiko answered 31/5 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.