IT虾米网

打开IOS设备的闪光灯代码

wyy 2018年06月23日 手机开发 1004 0
- (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等