Reputation: 1877
Error Log: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[AVCaptureMetadataOutput setMetadataObjectTypes:] - unsupported type found. Use -availableMetadataObjectTypes.' * First throw call stack:
This is the availableMetadataObjectTypes in debugger log. I don't understand why this is empty.
(lldb) po [output availableMetadataObjectTypes] <__NSArrayM 0x810ae990>()
Here is the code NSError* error;
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
];
}
Upvotes: 0
Views: 2100
Reputation: 36074
You should check availableMetadataObjectTypes
, but if you haven't added an input device, the list will be empty.
The hint comes from a comment on availableMetadataObjectTypes
in AVCaptureOutput.h
:
Available metadata object types are dependent on the capabilities of the AVCaptureInputPort to which this receiver's AVCaptureConnection is connected.
e.g. my back camera supports aztec and 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];
Upvotes: 7