gpt4 book ai didi

ios - 处理此错误的最佳方法? [AVCaptureFigVideoDevice setTorchModeOnWithLevel :error:]: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-29 11:00:09 25 4
gpt4 key购买 nike

如果设备不支持 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 时,是否有更好/有效的检测方法?

最佳答案

首先,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,但这适用于您不确定它是否具有特定方法的任何类。

关于ios - 处理此错误的最佳方法? [AVCaptureFigVideoDevice setTorchModeOnWithLevel :error:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16288521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com