在我的应用程序中,我需要确定当前正在使用哪台摄像机并切换摄像机,即将摄像机切换到前置摄像头我已实施以下代码来自Check which camera is currently in use in iOS Application
AVCaptureDevicePosition currentCameraPosition = [[VideoInputDevice device] position];
if (currentCameraPosition == AVCaptureDevicePositionBack)
{
currentCameraPosition = AVCaptureDevicePositionFront;
}
else
{
currentCameraPosition = AVCaptureDevicePositionBack;
}
AVCaptureDevice *backFacingCamera = nil;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
{
if ([device position] == currentCameraPosition)
{
backFacingCamera = device;
}
}
NSLog(backFacingCamera ? @"Yes":@"No");
但得错了答案
答案 0 :(得分:0)
您的代码看起来很好。获得结果后,将值赋给变量
- (void)frontCamera {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device position] == AVCaptureDevicePositionFront) {
//Front camera is used
}
}
}