作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果设备不支持 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/
我的变量: var torchLevel : Float = 0.0 我的切换功能: func toggleFlash() { let device = AVCaptureDevice
我正在使用这种方法打开手电筒: - (void)checkTorch { for (AVCaptureDevice *device in [AVCaptureDevice devices])
如果设备不支持 LED 调光,我正尝试关闭手电筒应用中的图像。 NSError* outError; BOOL success = [device setTorchModeOnWi
我是一名优秀的程序员,十分优秀!