如何确定我的iOS设备是否装有手电筒? [英] How can I determine whether my iOS device has a torch light?
本文介绍了如何确定我的iOS设备是否装有手电筒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我可以选择使用手电筒.但是,只有iPhone 4和iPhone 4S带有手电筒.其他设备没有手电筒.如何找到当前的设备型号?请帮我.预先感谢.
In my application I have the option for a torch light. Howevver, only iPhone 4 and iPhone 4S have torch lights. Other devices do not have the torch light. How can I find the current device model? Please help me. Thanks in advance.
推荐答案
您不应使用设备模型作为功能是否存在的指示.而是使用可以准确告诉您该功能是否存在的API.
You should not use the device model as an indicator of whether a feature is present. Instead, use the API that tells you exactly if the feature is present.
您要使用AVCaptureDevice
的-hasTorch
属性:
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
NSMutableArray *torchDevices = [[NSMutableArray alloc] init];
BOOL hasTorch = NO;
for (AVCaptureDevice *device in devices) {
if ([device hasTorch]) {
[torchDevices addObject:device];
}
}
hasTorch = ([torchDevices count] > 0);
更多信息,请参见 AVCaptureDevice类参考
这篇关于如何确定我的iOS设备是否装有手电筒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文