Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureMetadataOutput setMetadataObjectTypes: unspported type found

Tags:

ios7

qr-code

I used ios7 API to scan QRcode , code as bellow:

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

I got crashes 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]

anyone had met this?

like image 795
Ichagall Avatar asked Aug 25 '14 07:08

Ichagall


1 Answers

You must add the output to session before set the metadataObjectTypes. I meet the 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;
}
like image 83
firelyu Avatar answered Sep 28 '22 08:09

firelyu