1. 程式人生 > >iOS應用中開啟 手電筒/閃光燈 的方法

iOS應用中開啟 手電筒/閃光燈 的方法

-(void)openFlashlight
{
    AVCaptureDevice * device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (device.torchMode == AVCaptureTorchModeOff) {
        [device lockForConfiguration:nil];
        [device setTorchMode:AVCaptureTorchModeOn];
        [device unlockForConfiguration];
        [openFlashLightButton setTitle:@"關燈" forState:UIControlStateNormal];
    }else{
        [device lockForConfiguration:nil];
        [device setTorchMode:AVCaptureTorchModeOff];
        [device unlockForConfiguration];
        [openFlashLightButton setTitle:@"開燈" forState:UIControlStateNormal];
    }
}