Barcode scanning exclude AVmetadaTypeFace

133 views Asked by At

I'm developing a barcode scanner app using AVFoundation. My app successfully captures barcode data but it crash when detect FaceObjectType. How can we exclude this type from being detected to prevent crashing?

I'm using this:

captureMetadataOutput.metadataObjectTypes = [captureMetadataOutput availableMetadataObjectTypes];
3

There are 3 answers

0
Vinod Shimpi On

Its a bit late, but I think it will help someone who have the same issue. For Preventing crash, you need to handle the AVMetadataObject(https://developer.apple.com/documentation/avfoundation/avmetadataobject), So my suggestion for this is as below (swift 3.0)

for metadataObject in metadataObjects {
     if (metadataObject as AnyObject).type == AVMetadataObjectTypeFace {
                return
            }
        }
0
Faysal Ahmed On

You will fix the supported object type by using this

  NSArray *supportedType =[NSArray arrayWithObjects:
                         AVMetadataObjectTypeCode39Code,
                         AVMetadataObjectTypeCode39Mod43Code,
                         AVMetadataObjectTypeCode93Code,
                         AVMetadataObjectTypeCode128Code,
                         AVMetadataObjectTypeEAN8Code,
                         AVMetadataObjectTypeEAN13Code,
                         AVMetadataObjectTypeAztecCode,
                         AVMetadataObjectTypePDF417Code,
                         AVMetadataObjectTypeQRCode, nil];

captureMetadataOutput.metadataObjectTypes = supportedType;

instead of

captureMetadataOutput.metadataObjectTypes = [captureMetadataOutput availableMetadataObjectTypes];

This will help.