Enabling the device's flash unit during an AR session can help improve visibility.
Check that the current camera configuration supports flash
Not all camera configurations support enabling a flash unit. Before enabling the flash or offering users the option to enable the flash, ensure that the flash unit is available for the active camera configuration:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
return device.hasTorch;
}
return false;
Enable the flash unit
Enable the flash unit by configuring the AR session with
AVCaptureTorchModeOn
:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
if (device.hasTorch) {
NSError *error = nil;
if ([device lockForConfiguration:&error]) {
device.torchMode = AVCaptureTorchModeOn;
[device unlockForConfiguration];
} else {
return;
}
}
}
Disable the flash unit
Disable the flash unit by configuring the AR session with
AVCaptureTorchModeOff
:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
if (device.hasTorch) {
NSError *error = nil;
if ([device lockForConfiguration:&error]) {
device.torchMode = AVCaptureTorchModeOff;
[device unlockForConfiguration];
} else {
return;
}
}
}