Computer Vision

Live scanning QR codes in iOS using Vision framework

Photo by Albert Hu on Unsplash

Getting started

1. Download the starter project

cd $HOME
curl -o -L -s
unzip -q
cd vision_qr_codes_scanning-starter/
open -a Xcode qr_codes_scanning.xcodeproj

2. Extracting QR codes using Vision framework

private func extractQRCode(fromFrame frame: CVImageBuffer) -> String? {
import Vision
let barcodeRequest = VNDetectBarcodesRequest()
barcodeRequest.symbologies = [.QR]
private let sequenceHandler = VNSequenceRequestHandler()
try? self.sequenceHandler.perform([barcodeRequest], on: frame)
guard let results = barcodeRequest.results as? [VNBarcodeObservation], let firstBarcode = results.first?.payloadStringValue else {
return nil
return firstBarcode
if let barcode = self.extractQRCode(fromFrame: frame) {
print("did extract barcode \(barcode)")
QR code
results in the console


Final thoughts

Senior iOS Engineer @ Onfido. Writing weekly blogs on iOS and programming. Follow me to stay tuned!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store