我有以下代码来打开手电筒和闪光灯:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]) {
[self.session beginConfiguration];
[device lockForConfiguration:nil];
if(self.flashlightOn == YES)
{
[device setTorchMode:AVCaptureTorchModeOn];
[device setFlashMode:AVCaptureFlashModeOn];
NSLog(@"TurnFlashOn");
}
else
{
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
NSLog(@"TurnFlashOff");
}
[device unlockForConfiguration];
[self.session commitConfiguration];
但是,如果调用代码我的会话似乎冻结,如果我删除 [device setTorchMode:] 部分一切正常。有人知道这里发生了什么吗?
编辑:它仅在没有 IDE 的情况下运行应用程序时出现 -> 单独运行