Project

General

Profile

BitmapToolkit Scol plugin
CameraTorchIOS.mm
Go to the documentation of this file.
1#import <AVFoundation/AVFoundation.h>
2
3void turnTorchOn(bool state)
4{
5 // check if flashlight available
6 Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
7 if (captureDeviceClass != nil)
8 {
9 AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
10 if ([device hasTorch] && [device hasFlash])
11 {
12 [device lockForConfiguration:nil];
13 if (state)
14 {
15 [device setTorchMode:AVCaptureTorchModeOn];
16 [device setFlashMode:AVCaptureFlashModeOn];
17 }
18 else
19 {
20 [device setTorchMode:AVCaptureTorchModeOff];
21 [device setFlashMode:AVCaptureFlashModeOff];
22 }
23 [device unlockForConfiguration];
24 }
25 }
26}
void turnTorchOn(bool state)
enable or disable camera flash