首页 > 代码库 > ios闪光灯调用

ios闪光灯调用

引入

#import <AVFoundation/AVFoundation.h>


打开闪光灯

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    
    

    if (![device hasTorch]) {//判断是否有闪光灯
        
        NSLog(@"no torch");
        
    }else{
        
        [device lockForConfiguration:nil];//锁定闪光灯

        [device setTorchMode: AVCaptureTorchModeOn];//打开闪光灯
    
        [device unlockForConfiguration];  //解除锁定
    
    }

关闭闪光灯
[device setTorchMode: AVCaptureTorchModeOff];