default(_:for:position:)
Returns the default device for the specified device type, media type, and position.
Declaration
class func `default`(_ deviceType: AVCaptureDevice.DeviceType, for mediaType: AVMediaType?, position: AVCaptureDevice.Position) -> AVCaptureDevice?Parameters
- deviceType:
The type of capture device to request, such as Builtinwideanglecamera.
- mediaType:
The type of media to request capture of, such as Video or Audio.
- position:
The position of capture device to request relative to system hardware (front- or back-facing). Pass Unspecified to search for devices regardless of position.
Mentioned in
Return Value
The default system device, or nil if no device currently exists that satisfies the specified criteria.
Discussion
Use this method to select the system default capture device for a given scenario. For example, to obtain the dual camera on supported hardware and fall back to the standard wide-angle camera otherwise, call this method twice, as shown below.
// The app's default camera.
var defaultCamera: AVCaptureDevice? {
// Find the built-in dual camera, if it exists.
if let device = AVCaptureDevice.default(.builtInDualCamera,
for: .video,
position: .back) {
return device
}
// Find the built-in wide-angle camera, if it exists.
if let device = AVCaptureDevice.default(.builtInWideAngleCamera,
for: .video,
position: .back) {
return device
}
return nil
}