我有我的Flashligh應用程序工作完美。出於某種原因,我每次點擊手電筒按鈕的速度非常快,應用程序只是凍結,並沒有做任何事情。當我調用AVCaptureSession stopRunning時,它似乎凍結了。下面是我的切換手電筒方法的代碼。我也希望這種方法最終被稱爲頻閃功能。iPhone手電筒應用程序崩潰時,快速輕按按鈕
- (void)toggleFlashlight{
if (isTorchOn) {
// Start session configuration
[session beginConfiguration];
[device lockForConfiguration:nil];
// Set torch to on
[device setTorchMode:AVCaptureTorchModeOn];
[device unlockForConfiguration];
[session commitConfiguration];
[session startRunning];
}
else {
[session stopRunning];
[session release];
session = nil;
session = [[AVCaptureSession alloc] init];
// Create device input and add to current session
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
[session addInput:input];
// Create video output and add to current session
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[session addOutput:output];
[output release];
}
}