Select the front or back camera, or use advanced features like the TrueDepth camera or dual camera.
Devices offer many options for capturing photos and video, including front- and back-facing cameras, dual cameras, and the TrueDepth camera. Choosing the appropriate camera automatically or offering a user interface for camera selection is an important part of developing any app with camera features.
Quickly Choose a Default Device
If you know exactly what kind of capture devices you’re looking for, use one of the
AVCapture convenience methods to select a default device. For example, the code below selects the best available back-facing camera: either the dual camera on supported devices, or the single (wide-angle) camera on single-camera devices.
Sort and Filter Devices with a Discovery Session
To see the entire set of devices matching certain criteria so that you can use your own logic to choose one, use the
AVCapture class. First, create a discovery session for the kinds of devices you need:
Then, read the discovery session’s
devices list to find matching devices and choose one that suits your needs. The discovery session automatically sorts its
devices list based on the device types you asked for, so you can use the array order to find the best device with certain features. For example, because the discovery session shown above searches for depth-capable devices before the wide-angle camera and allows any device position, the first item in its devices list matching a specified position is the best depth capture device for that position (or a fallback device):