Type Method

defaultDeviceWithDeviceType:mediaType:position:

Returns the default device for the specified device type, media type, and position.

Declaration

+ (AVCaptureDevice *)defaultDeviceWithDeviceType:(AVCaptureDeviceType)deviceType mediaType:(AVMediaType)mediaType position:(AVCaptureDevicePosition)position;

Parameters

deviceType

The type of capture device to request, such as AVCaptureDeviceTypeBuiltInWideAngleCamera. See AVCaptureDeviceType.

mediaType

The type of media to request capture of, such as AVMediaTypeAudio. See Media Types.

position

The position of capture device to request relative to system hardware (front- or back-facing). Pass AVCaptureDevicePositionUnspecified to search for devices regardless of position.

Return Value

The system default device for the specified combination of device type, media type, and position, or nil if no currently available device satisfies the specified criteria.

Discussion

Use this method to easily 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.

- (AVCaptureDevice *)defaultCamera {
    AVCaptureDevice *device;
    device = [AVCaptureDevice defaultDeviceWithDeviceType: AVCaptureDeviceTypeBuiltInDuoCamera
                                                mediaType: AVMediaTypeVideo
                                                 position: AVCaptureDevicePositionBack];
    if (device != nil) {
        return device;
    }
    device = [AVCaptureDevice defaultDeviceWithDeviceType: AVCaptureDeviceTypeBuiltInWideAngleCamera
                                                mediaType: AVMediaTypeVideo
                                                 position: AVCaptureDevicePositionBack];
    if (device != nil) {
        return device;
    }
    return nil;
}

See Also

Discovering Devices

+ deviceWithUniqueID:

Returns the device with a given ID.

+ defaultDeviceWithMediaType:

Returns the default device used to capture data of a given media type.

AVCaptureDevicePosition

Constants to specify the position of a capture device.

AVCaptureDeviceType

Values identifying the capture device’s type.

AVCaptureDeviceDiscoverySession

A query for finding and monitoring available capture devices.

AVCaptureDeviceWasConnectedNotification

Posted when a new device becomes available.

AVCaptureDeviceWasDisconnectedNotification

Posted when an existing device becomes unavailable.

+ devices

Returns an array of the available capture devices on the system.

Deprecated
+ devicesWithMediaType:

Returns an array of the devices able to capture data of a given media type.

Deprecated

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software