1

如果设备不支持 LED 调光,我正在尝试关闭我的手电筒应用程序中的图像。

  NSError* outError;
        BOOL success = [device setTorchModeOnWithLevel:brightnessLevel error:&outError];
        if(!success){
            [self.lightDialIndicator setHidden: YES];
            self.lightDial.image = [UIImage imageNamed:@"light_dial_disabled.png"];
        }

但我的应用程序因以下错误而崩溃

[AVCaptureFigVideoDevice setTorchModeOnWithLevel:error:]: unrecognized selector sent to instance 0x73ad460

有什么更好的/可行的方法来检测设备何时不允许我使用setTorchModeOnWithLevel

4

1 回答 1

2

首先,setTorchModeOnWithLevelAVCaptureDevice类的属性。

其次,如果你想测试一个类是否可以响应你调用的某个选择器,你可以使用这个:

BOOL isSuccessful = NO;
if ([device respondsToSelector:@selector(setTorchModeOnWithLevel:error:)]) {
    NSError* outError;
    isSuccessful = [device setTorchModeOnWithLevel:brightnessLevel error:&outError];
}
if (!isSuccessful) {
    [self.lightDialIndicator setHidden: YES];
     self.lightDial.image = [UIImage imageNamed:@"light_dial_disabled.png"];
}

您没有在示例中展示您是如何实例化device的,但这适用于您不确定它是否具有特定方法的任何类。

于 2013-04-29T21:57:45.277 回答