- (void) turnTorchOn: (bool) on { 
 
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); 
if (captureDeviceClass != nil) { 
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    if ([device hasTorch] && [device hasFlash]){ 
 
        [device lockForConfiguration:nil]; 
        if (on) { 
            [device setTorchMode:AVCaptureTorchModeOn]; 
            [device setFlashMode:AVCaptureFlashModeOn]; 
            torchIsOn = YES; 
        } else { 
            [device setTorchMode:AVCaptureTorchModeOff]; 
            [device setFlashMode:AVCaptureFlashModeOff]; 
            torchIsOn = NO;             
        } 
        [device unlockForConfiguration]; 
    } 
} 
}
发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

iOS常用数据校验方法,验证手机号,信用卡号,电话号码,邮编,Email等详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。