AVCaptureDevice
has both hasFlash
and hasTorch
properties (and similar other methods/properties). What is the difference between the flash and the torch?
Also, do any iOS devices exist with only one of the above?
On iPhone devices both cameras have flash: back camera has a LED camera flash and can operate in a torch mode and front camera uses display as a flash (displaying for the short period of time white screen emits enough light) but display cannot be used as a torch.
Checking [device hasFlash] to set LED flash ON/OFF programmatically from the list of AVCaptureDevice:
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
is not enough, since both cameras will pass condition [device hasFlash], but setting [device setTorchMode:AVCaptureTorchModeOn] for the front camera may cause app crash. The best is probably to check both:
if ([device hasFlash] && [device hasTorch]) {
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn]; // for example
[device unlockForConfiguration];
}