所以我有一个 UISwitch 用于我的叠加层,每次相机出现时都会出现。现在,当我打开按钮或向右滑动开关(开启模式)时,手电筒就会打开。但是当我把它切换到左边时,它并没有关闭。我究竟做错了什么?
- (void)mySwitchPressed {
if (self.mySwitch.on) {
AVCaptureDevice *flashLight = [AVCaptureDevice
defaultDeviceWithMediaType:AVMediaTypeVideo];
if([flashLight isTorchAvailable] && [flashLight
isTorchModeSupported:AVCaptureTorchModeOn]) {
BOOL success = [flashLight lockForConfiguration:nil];
if(success) {
[flashLight setTorchMode:AVCaptureTorchModeOn];
[flashLight unlockForConfiguration];
}
} else {
AVCaptureDevice *flashLight = [AVCaptureDevice
defaultDeviceWithMediaType:AVMediaTypeVideo];
if([flashLight isTorchAvailable] && [flashLight
isTorchModeSupported:AVCaptureTorchModeOn]) {
BOOL success = [flashLight lockForConfiguration:nil];
if(success) {
[flashLight setTorchMode:AVCaptureTorchModeOff];
[flashLight unlockForConfiguration];
}
}
}
}
}