Returns the default device for the specified device type, media type, and position.
Language
- Swift
- Objective-C
SDK
- iOS 10.0+
Declaration
+ (AVCaptureDevice *)defaultDeviceWithDeviceType:(AVCaptureDeviceType)deviceType mediaType:(NSString *)mediaType position:(AVCaptureDevicePosition)position;
Parameters
deviceTypeThe type of capture device to request, such as
AVCaptureDeviceTypeBuiltInWideAngleCamera. SeeAVCaptureDeviceType.mediaTypeThe type of media to request capture of, such as
AVMediaTypeAudio. See Media Types.positionThe position of capture device to request relative to system hardware (front- or back-facing). Pass
AVCaptureDevicePositionUnspecifiedto 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;
}