Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine whether my iOS device has a torch light?

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.

like image 605
Yuvaraj.M Avatar asked Dec 28 '22 09:12

Yuvaraj.M


1 Answers

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.

In your case, you want to use AVCaptureDevice's -hasTorch property:

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);

More information is available in the AV Foundation Programming Guide and the AVCaptureDevice Class Reference

like image 143
Martin Gordon Avatar answered Mar 24 '23 23:03

Martin Gordon