如果设备不支持 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
时,是否有更好/有效的检测方法?
最佳答案
首先,setTorchModeOnWithLevel
是 AVCaptureDevice
类的一个属性。
其次,如果你想测试一个类是否可以响应你正在调用它的某个选择器,你可以使用这个:
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
,但这适用于您不确定它是否具有特定方法的任何类。
关于ios - 处理此错误的最佳方法? [AVCaptureFigVideoDevice setTorchModeOnWithLevel :error:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16288521/