Mic*_*lle 0 objective-c avfoundation
错误日志:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' * - [AVCaptureMetadataOutput setMetadataObjectTypes:] - 找不到支持的类型.使用-availableMetadataObjectTypes.'*第一次抛出调用堆栈:
这是调试器日志中的availableMetadataObjectTypes.我不明白为什么这是空的.
(lldb)po [输出availableMetadataObjectTypes] <__ NSArrayM 0x810ae990>()
这是代码NSError*错误;
session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetHigh];
AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput* deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if ([session canAddInput:deviceInput]) {
[session addInput:deviceInput];
}
previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self scannerView] layer];
[rootLayer setMasksToBounds:YES];
[previewLayer setFrame:CGRectMake(self.scannerView.frame.origin.x, self.scannerView.frame.origin.y, self.scannerView.frame.size.width, self.scannerView.frame.size.height)];
[rootLayer insertSublayer:previewLayer atIndex:0];
_labelBarcode = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 300, 40)];
_labelBarcode.backgroundColor = [UIColor darkGrayColor];
_labelBarcode.textColor = [UIColor whiteColor];
[self.scannerView addSubview:_labelBarcode];
[self rotatePreviewLayerToDeviceOrientation];
[session startRunning];
AVCaptureMetadataOutput* output = [[AVCaptureMetadataOutput alloc] init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
if ([session canAddOutput:output]) {
[session addOutput:output];
}
[output availableMetadataObjectTypes];
output.metadataObjectTypes = @[
AVMetadataObjectTypeAztecCode,
AVMetadataObjectTypeCode128Code,
AVMetadataObjectTypeCode39Code,
AVMetadataObjectTypeCode39Mod43Code,
AVMetadataObjectTypeCode93Code,
AVMetadataObjectTypeEAN13Code,
AVMetadataObjectTypeEAN8Code
];
Run Code Online (Sandbox Code Playgroud)
}
您应该检查availableMetadataObjectTypes,但如果您尚未添加输入设备,则列表将为空.
提示来自availableMetadataObjectTypes于 AVCaptureOutput.h:
可用的元数据对象类型取决于此接收器的AVCaptureConnection所连接的AVCaptureInputPort的功能.
例如我的后置摄像头支持aztec和code128.
NSError *error;
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
// Check input and error here.
[session addInput:input];
AVCaptureMetadataOutput* output = [[AVCaptureMetadataOutput alloc] init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
if ([session canAddOutput:output]) {
[session addOutput:output];
}
// NOW try adding metadata types
session.metadataObjectTypes = @[AVMetadataObjectTypeAztecCode,
AVMetadataObjectTypeCode128Code];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1672 次 |
| 最近记录: |