Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureMetadataOutput setMetadataObjectTypes unsupported type found

I know there are someone have ask this question.But it is a sorry i donot find the answer.

dispatchQueue = dispatch_queue_create("myQueue", NULL);
[captureMetadaOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
//  [captureMetadaOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];
//  设置条码类型
captureMetadaOutput.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];

i got crashes info from Crashlytics:

[AVCaptureMetadataOutput setMetadataObjectTypes:] - unsupported type found. Use -availableMetadataObjectTypes.

like image 428
Huichuang Xuanyuan Avatar asked Jun 26 '15 02:06

Huichuang Xuanyuan


People also ask

What is Avan avcapturemetadataoutput?

An AVCaptureMetadataOutput object intercepts metadata objects emitted by its associated capture connection and forwards them to a delegate object for processing. You can use instances of this class to process specific types of metadata included with the input data.

How do I use the output class of the avcapturesession?

You can use instances of this class to process specific types of metadata included with the input data. You use this class the way you do other output objects, typically by adding it as an output to an AVCaptureSession object.

What is the metadataobjecttypes array?

var metadataObjectTypes: [AVMetadataObject.ObjectType]! An array of strings identifying the types of metadata objects to process. A rectangle of interest for limiting the search area for visual metadata.


3 Answers

We have to add the output to session first, and then we can set the metadataObjectTypes.

like image 191
Alan Luo Avatar answered Sep 22 '22 11:09

Alan Luo


you need to do like this:

        if ([_captureSession canAddOutput:self.metadataOutput]) {
        [_captureSession addOutput:self.metadataOutput];
        // 这里注意,必须先将metadataOutput 加入到session,然后才能设置metadataObjectTypes,注意顺序,不然会crash
        self.metadataOutput.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
        [self.metadataOutput setMetadataObjectsDelegate:self queue:_videoDataOutputQueue];
    }
like image 33
brownfeng Avatar answered Sep 23 '22 11:09

brownfeng


It is because of you close the camera authorization. You can open your camera authorization, then open canner to scan QRCode. The blow give typical examples:

AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 
if(status == AVAuthorizationStatusAuthorized) {  
    // authorized  
    [self setupCamera];  
} else {  
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tips" message:@"Authorization is required to use the camera, please check your permission settings: Settings> Privacy> Camera" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
        [alert show];  
}
like image 27
Whyte.Lee Avatar answered Sep 19 '22 11:09

Whyte.Lee