iOS 闪光灯的打开、关闭

释放双眼,带上耳机,听听看~!
- (void)openFlash:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    if (sender.isSelected == YES) { //打开闪光灯
        AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        NSError *error = nil;
        
        if ([captureDevice hasTorch]) {
            BOOL locked = [captureDevice lockForConfiguration:&error];
            if (locked) {
                captureDevice.torchMode = AVCaptureTorchModeOn;
                [captureDevice unlockForConfiguration];
            }
        }
    }else{//关闭闪光灯
        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        if ([device hasTorch]) {
            [device lockForConfiguration:nil];
            [device setTorchMode: AVCaptureTorchModeOff];
            [device unlockForConfiguration];
        }
    }
    
}

人已赞赏
iOS文章

iOS 文本输入控制(献上框架)

2019-10-16 2:00:09

iOS文章

iOS AppDelegate入口解耦

2019-10-16 9:05:38

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索