检查iOS应用程序中当前正在使用哪个相机 [英] Check which camera is currently in use in iOS Application

查看:873
本文介绍了检查iOS应用程序中当前正在使用哪个相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个应用程序,该应用程序有一个自定义视图,用于使用相机拍照,类似于Apple的AVCam。在它,我想让一个按钮消失,并重新出现闪光灯图标每次相机切换。 IE当使用前置摄像头时,闪光按钮不应该在那里,当使用后面的时候应该这样!

I'm writing an app which has a custom made view for taking photos with the Camera, similar to Apple's AVCam. In it, I want to make a button disappear and re-appear for the flash icon every time the camera is switched. IE When using the front camera, the flash button shouldn't be there and when using the back it should!

我现在的代码是:

  AVCaptureDevicePosition position = [[videoInput device] position];

    if (position == AVCaptureDevicePositionBack) {
  self.flashButton.hidden == YES;
}

但是它提出了一个错误videoInput和我不确定为什么...您可以指示我的任何文档或代码中的更改的想法将非常感谢!

But it comes up with an error on the videoInput and I'm not sure why... Any documentation you could direct me to or ideas for changes in my code would be much appreciated!

编辑

基本上,为什么会出现这个代码的使用未声明的标识符的错误:

Just basically specifically why does it come up with the error of 'use of undeclared identifier' with this code:

AVCaptureDevicePosition position = [[videoInput device] position];


推荐答案

以下代码可能会帮助您:

The below code might help you :

AVCaptureDeviceInput *newVideoInput;
AVCaptureDevicePosition currentCameraPosition = [[videoInput 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;
    }
}
newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];

这篇关于检查iOS应用程序中当前正在使用哪个相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆