<br />

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`](https://developer.apple.com/documentation/avfoundation/avcapturetorchmode/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;
            }
        }
    }

> [!NOTE]
> **Note:** Configuring [`AVCaptureTorchModeOn`](https://developer.apple.com/documentation/avfoundation/avcapturetorchmode/avcapturetorchmodeon) with a camera configuration that does not support a flash unit will have no effect.

## Disable the flash unit

Disable the flash unit by configuring the AR session with
[`AVCaptureTorchModeOff`](https://developer.apple.com/documentation/avfoundation/avcapturetorchmode/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;
            }
        }
    }