Reputation: 657
Xcode 12 / Swift 5
AVfoundation
I followed this tutorial for barcode scanner http://www.wepstech.com/bar-qr-code-ios-with-swift-5/
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
if let metadataObject = metadataObjects.first {
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return }
guard let stringValue = readableObject.stringValue else { return }
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)
captureSession.stopRunning()
parent.presentationMode.wrappedValue.dismiss()
}
}
It returns the scanned value,
but how to get the barcode TYPE ; to know if it scanned qrcode, code128...
Upvotes: 0
Views: 372
Reputation: 236360
You can switch your metadataObject
's type
property and check which one you've got:
switch metadataObject.type {
case .qr:
print("qrcode")
case .code128:
print("code128")
default:
print("other type")
}
Upvotes: 2