The code is modified from Apple Sample Code: https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/streaming_depth_data_from_the_truedepth_camera
Hardware requirements: Mac OS with Xcode 11.0+, iPhone with TrueDepth Camera and iOS 12.0+
You need a Mac OS with Xcode 11.0+ to build the code and an iPhone with TrueDepth Camera, e.g., iPhone X or newer, to run the program.
To build the code, open the project with Xcode, and you should be able to compile it. After building it successfully, connect your iphone and install it.
You will see something like below on your iphone.
NOTE: Once the app is opened, it automatically starts to capture RGB-D images and save them into iPhone's album. It won’t stop until you close the app.
The captured RGB-D images will be saved in the album, like the snapshot below. Then you can freely export them from the album.