相对于Retina Flash检测相机闪光灯

时间:2016-06-09 10:11:29

标签: ios objective-c uiimagepickercontroller

我们正在使用UIImagePickerController自定义UI按钮。我遇到了一个问题,我找不到用于检测Retina Flash的API。 Apple sample code我发现有同样的问题。

这是我发现要检查Flash的所有内容。正如你所看到的那样,在使用后置摄像头时iPhone 6S有Retina Flash无法知道。

- (void)flashTest {

    if ([UIImagePickerController isFlashAvailableForCameraDevice:_delegate.imagePickerController.cameraDevice]) {
        NSLog(@"isFlashAvailableForCameraDevice = YES");
    } else {
        NSLog(@"isFlashAvailableForCameraDevice = NO");
    }

    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if ([device hasFlash]) {
        NSLog(@"device hasFlash - YES");
    } else {
        NSLog(@"device hasFlash - NO");
    }

    if ([device isFlashActive]) {
        NSLog(@"Flash is not active");
    } else {
        NSLog(@"Flash IS active");
    }

    if ([device isFlashModeSupported:AVCaptureFlashModeOn]) {
        NSLog(@"Flash mode supported YES");
    } else {
        NSLog(@"Flash Mode not supproted.");
    }
}

输出:

iPod Touch Back
----------------
isFlashAvailableForCameraDevice = YES  
device hasFlash - YES  
Flash IS active  
Flash mode supported YES  

iPod Touch Front
----------------
isFlashAvailableForCameraDevice = NO  
device hasFlash - YES  
Flash IS active  
Flash mode supported YES  

iPhone 6S Back
----------------
isFlashAvailableForCameraDevice = YES  
device hasFlash - YES  
Flash IS active
Flash mode supported YES  

iPhone 6S Front
---------------
isFlashAvailableForCameraDevice = NO  
device hasFlash - YES  
Flash IS active
Flash mode supported YES

iPad Air Back
--------------
isFlashAvailableForCameraDevice = NO
device hasFlash - NO
Flash IS active
Flash Mode not supproted.

iPad Air Front
--------------
isFlashAvailableForCameraDevice = NO
device hasFlash - NO
Flash IS active
Flash Mode not supproted.

文件说。

  

Retina Flash

     

在支持的设备上,显示屏亮度可以短暂增加到通常最大照度的3倍,以用作前置摄像头的闪光灯。使用此功能时,显示屏也会改变其颜色输出,以达到与后置摄像头的True Tone闪光灯相同的效果。没有单独的API控制此功能 - 在支持的设备上,AVCaptureDevice hasFlash属性反映了前置摄像头Retina Flash的可用性。与后置摄像头一样,您可以使用isFlashModeSupported:和flashMode属性来控制闪光灯。

我提交了一个错误。 http://www.openradar.appspot.com/radar?id=4941073017208832

更新

我检查后置和后置摄像头。我打电话给flashTest两次:最初和我在我的自定义用户界面中使用以下代码翻转相机后。

_delegate.imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;

TL; DR;
没有办法确定Flash是否可用。使用iPod Touch套件hasFlash即使我使用前置摄像头也会返回YESisFlashAvailableForCameraDevice分别为iPod Back Front返回正确的YESNO,但在iPhone 6S上则返回相同的YESNO,尽管它有Retina Flash。

3 个答案:

答案 0 :(得分:0)

Retina闪光灯仅适用于前置摄像头,不适用于后置摄像头。在这里你检查了后置摄像头。所以,它返回no。

答案 1 :(得分:0)

您需要检查您的有源相机设备是否是前置摄像头并且它有可用的闪光灯,这意味着该设备具有Retina闪光灯,因为从6s开始只有Retina设备有前置摄像头闪光灯。代码在这里 -

-(AVCaptureDevice *)getFrontCameraDevice
{
    NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    AVCaptureDevice *captureDevice = nil;
    for (AVCaptureDevice *device in videoDevices)
    {
        if (device.position == AVCaptureDevicePositionFront)
        {
            captureDevice = device;
            break;
        }
    }

    return captureDevice;
}

-(BOOL)hasRetinaFlash:(AVCaptureDevice *)device
{
    if (device.position == AVCaptureDevicePositionFront && device.hasFlash) {
         return YES;
    }

    return NO;
}

答案 2 :(得分:0)

#import "AVCaptureDevice+Extension.h"

@implementation AVCaptureDevice (Extension)

-(BOOL)hasRetinaFlash
{
    if(self.position == AVCaptureDevicePositionFront && self.hasFlash) {
        return YES;
    }

    return NO;
}

-(BOOL)isFrontCamera
{
    return (self.position == AVCaptureDevicePositionFront);
}


-(BOOL)isBackCamera
{
    return (self.position == AVCaptureDevicePositionBack);
}