AVCaptureMetadataOutput setMetadataObjectTypes: unsupported type detected

I used the ios7 API to scan the QR code, the code below:

AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init]; [self.captureSession addOutput:output]; [output setMetadataObjectsDelegate:self queue:captureOutputBufferQueue]; output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode]; 

I got crash info from Crashlytics:

  NSInvalidArgumentException *** -[AVCaptureMetadataOutput setMetadataObjectTypes:] - unsupported type found. Use - availableMetadataObjectTypes. Thread : Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x303b9f83 __exceptionPreprocess + 130 1 libobjc.A.dylib 0x3ab6accf objc_exception_throw + 38 2 AVFoundation 0x2f2f7c29 -[AVCaptureMetadataOutput rectOfInterest] 

Has anyone met this?

+7
ios7 qr-code
source share
1 answer

You must add output to the session before setting metadataObjectTypes. I encounter an error and use the following code, fix it.

 @property (nonatomic, strong) AVCaptureMetadataOutput *output; @property (nonatomic, strong) AVCaptureSession *session; - (AVCaptureMetadataOutput *)output { if (!_output) { _output = [[AVCaptureMetadataOutput alloc] init]; [_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; } return _output; } - (AVCaptureSession *)session { if (!_session) { _session = [[AVCaptureSession alloc] init]; [_session setSessionPreset:AVCaptureSessionPresetHigh]; if ([_session canAddInput:self.input]) { [_session addInput:self.input]; } if ([_session canAddOutput:self.output]) { [_session addOutput:self.output]; NSArray *typeList = self.output.availableMetadataObjectTypes; NSLog(@"availableMetadataObjectTypes : %@", typeList); self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode]; } } return _session; } 
+1
source share

All Articles