在使用拍照的时候崩了
lwy121810 opened this issue · comments
我是在使用pad真机运行的时候, 点击拍照上面第二个闪电按钮的时候崩溃的,崩溃在
- (void) closeFlashlight:(UIButton )sender{
// self.device.torchMode == AVCaptureTorchModeOff 判断
[self flashLightModel:^{
[self.device setTorchMode:AVCaptureTorchModeOff];//这一行
}];
}
崩溃信息为
相册Demo[12257:5168757] ** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureVideoDevice setTorchMode:] - the passed torchMode 0 is not supported by the device. Use -isTorchModeSupported: to discover valid torch modes.'
*** First throw call stack:
(0x1812f9900 0x180967f80 0x187584da0 0x100097664 0x100097290 0x1000975d4 0x186023e50 0x186023dcc 0x18600ba88 0x1860236e4 0x186023314 0x18601be30 0x185fec4cc 0x185fea794 0x1812b0efc 0x1812b0990 0x1812ae690 0x1811dd680 0x1826ec088 0x186054d90 0x1000857f0 0x180d7e8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
@lwy121810 你好,你可以看下最新代码看看效果,我换了这种方式来处理。
AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil]; //you must lock before setting torch mode
[device setTorchMode:isOn ? AVCaptureTorchModeOn : AVCaptureTorchModeOff];
[device unlockForConfiguration];
恩, 我刚刚又下载了一下, 不过还是崩溃
崩溃在- (void) setTorchOn:(BOOL)isOn
{
[self.device lockForConfiguration:nil]; //you must lock before setting torch mode
[self.device setTorchMode:isOn ? AVCaptureTorchModeOn : AVCaptureTorchModeOff];//这一行
[self.device unlockForConfiguration];
}
崩溃信息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureVideoDevice setTorchMode:] - the passed torchMode 0 is not supported by the device. Use -isTorchModeSupported: to discover valid torch modes.'
*** First throw call stack:
(0x1812f9900 0x180967f80 0x187584da0 0x1000f1cb4 0x1000f1e78 0x1000f192c 0x1000f1ddc 0x186023e50 0x186023dcc 0x18600ba88 0x1860236e4 0x186023314 0x18601be30 0x185fec4cc 0x185fea794 0x1812b0efc 0x1812b0990 0x1812ae690 0x1811dd680 0x1826ec088 0x186054d90 0x10013f168 0x180d7e8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
if ([self.device isTorchModeSupported:AVCaptureTorchModeOn] ||
[self.device isTorchModeSupported:AVCaptureTorchModeOff]) {
....
}
@lwy121810 我加了一个判断. 麻烦再试下
可以了, 不会蹦了, 不过这样的话上面的闪电按钮有什么用呢?点击好像没什么效果啊?
因为你的设备不支持闪光灯,o(╯□╰)o...
原来如此,现在我看ZLPhoto都是用的<AssetsLibrary/AssetsLibrary.h>这个库 , 不过这个库不是已经被PhotoKit取代了么? 您有没有想过更换为PhotoKit?因为最近在学习您这个库, 谢谢