打开IOS设备的闪光灯代码详解手机开发

- (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]; 
    } 
} 
}

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/3328.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论