2

I've implemented an QR-/Barcode reader in Swift using AVFoundation framework.

For supported types I added nearly all types available:

let supportedCodeTypes = [AVMetadataObjectTypeUPCECode,
                          AVMetadataObjectTypeCode39Code,
                          AVMetadataObjectTypeCode39Mod43Code,
                          AVMetadataObjectTypeCode93Code,
                          AVMetadataObjectTypeCode128Code,
                          AVMetadataObjectTypeEAN8Code,
                          AVMetadataObjectTypeEAN13Code,
                          AVMetadataObjectTypeAztecCode,
                          AVMetadataObjectTypePDF417Code,
                          AVMetadataObjectTypeQRCode,
                          AVMetadataObjectTypeDataMatrixCode,
                          AVMetadataObjectTypeITF14Code]

Now I want to add support for Code39Mod10 codes and Codabar barcodes, which is not available in the AVMetadataObjectTypes.

Is there a possibility to add custom AVMetadataObjectTypes or do I have to use some 3rd party scanner framework. And if so, can you suggest one?

mahega
  • 3,231
  • 4
  • 20
  • 32
  • Asking for 3rd-party libraries/plugins/etc. is considered off-topic for SO, so you can only really ask the 1st part of that. :P – underscore_d Apr 11 '18 at 08:46

1 Answers1

-1

Please check firebase it's allow to scan it ``` add AVCaptureVideoDataOutputSampleBufferDelegate on your view controller
setup live detection:-
self.view.layoutIfNeeded() session.sessionPreset = AVCaptureSession.Preset.photo let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)

    if captureDevice != nil
    {
        let deviceInput = try! AVCaptureDeviceInput(device: captureDevice!)
        let deviceOutput = AVCaptureVideoDataOutput()
        deviceOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
        deviceOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: DispatchQoS.QoSClass.default))
        session.addInput(deviceInput)
        session.addOutput(deviceOutput)
        
        let imageLayer = AVCaptureVideoPreviewLayer(session: session)
        imageLayer.frame = self.viewScanner.bounds
        imageLayer.videoGravity = .resizeAspectFill
        viewScanner.layer.addSublayer(imageLayer)
        viewScanner.bringSubviewToFront(imgScanner)
        session.startRunning()
    } <br/> implement delegate:- <br/> //MARK:- AVCaptureVideoDataOutputSampleBufferDelegate
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    if self.session.isRunning {
        if let barcodeDetector = self.barcodeDetector {
            
            let visionImage = VisionImage(buffer: sampleBuffer)
            
            barcodeDetector.detect(in: visionImage) { (barcodes, error) in
                if let error = error {
                    print(error.localizedDescription)
                    return
                }
                if barcodes!.count > 0 {
                    let barcode = barcodes?.first
                    if let decodeString = barcode?.rawValue {

                            print("\n======================= Barcode value =======================\n \(barcode!.rawValue!)")
                            self.session.stopRunning()
    
                    }
                }
            }
        }
    }
}