如果在iOS设置中禁用相机,则在AVCaptureDeviceInput处崩溃
我正在使用ZXing小部件扫描QRCode。如果用户从iOS设置禁用摄像头访问,我的应用程序将崩溃,如下所示: *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:*无法添加,因为设备不支持AVCaptureSessionPresetMedium。使用-[AVCaptureDevice supportsAVCaptureSessionPreset:] 有没有办法尝试并提示用户重新打开它 谢谢如果在iOS设置中禁用相机,则在AVCaptureDeviceInput处崩溃,ios,cocoa-touch,Ios,Cocoa Touch,我正在使用ZXing小部件扫描QRCode。如果用户从iOS设置禁用摄像头访问,我的应用程序将崩溃,如下所示: *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:*无法添加,因为设备不支持AVCaptureSessionPresetMedium。使用-[AVCaptureDevice supportsAVCaptureSessionPreset:] 有没有办法尝试并提示用户重新打开它 谢谢 Leo我在iPad1上也有同样的错误,我猜是因为iPad1没
Leo我在iPad1上也有同样的错误,我猜是因为iPad1没有摄像头。我这样做是为了解决车祸:
if([[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] supportsAVCaptureSessionPreset:AVCaptureSessionPresetMedium]){
// add code to open ZXingWidgetController
} else {
// show alert that device does not support
}
您可以使用以下代码,它与iOS 5+兼容
- (BOOL)backCameraIsReady
{
AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *inputDeviceError = nil;
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&inputDeviceError];
if (!captureInput) {
return NO;
} else {
return YES;
}
}