QR Codes en aplicaciones móviles: Generación nativa y escaneo
Both mobile platforms ship QR handling inside their own frameworks, which removes the third-party dependency from the build entirely. On iOS, the Vision framework detects and decodes symbols through VNDetectBarcodesRequest, filtering results by the .qr symbology and correcting orientation automatically, while Core Image generates them through the CIQRCodeGenerator filter with a selectable correction level. On Android, ML Kit supplies the scanning client through BarcodeScanning. The practical argument for native frameworks is twofold: nothing is added to the dependency tree, and camera performance is tuned by the platform vendor rather than by a library author working across devices.
QR Codes in Mobile Apps: Native Generation and Scanning
Integrating QR code generation and scanning into iOS and Android apps using native frameworks provides the best performance and user experience.
iOS: Vision Framework (Scanning)
iOS provides native QR scanning through the Vision framework:
import Vision
let request = VNDetectBarcodesRequest { request, error in
guard let results = request.results as? [VNBarcodeObservation] else { return }
for barcode in results {
if barcode.symbology == .qr {
print("QR data: \(barcode.payloadStringValue ?? "")")
}
}
}
Vision framework advantages: no third-party dependencies, Apple-optimised performance, automatic orientation correction.
iOS: Core Image (Generation)
Generate QR codes natively on iOS:
import CoreImage
let data = "https://example.com".data(using: .utf8)!
let filter = CIFilter(name: "CIQRCodeGenerator")!
filter.setValue(data, forKey: "inputMessage")
filter.setValue("M", forKey: "inputCorrectionLevel")
let ciImage = filter.outputImage!
Android: ML Kit (Scanning)
Google ML Kit provides reliable QR scanning:
val scanner = BarcodeScanning.getClient(
BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
.build()
)
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
for (barcode in barcodes) {
val data = barcode.rawValue
}
}
Android: ZXing (Generation)
Generate QR codes on Android using ZXing:
val writer = MultiFormatWriter()
val matrix = writer.encode(
"https://example.com",
BarcodeFormat.QR_CODE, 512, 512
)
UX Patterns
Camera scanning UX: - Show a viewfinder overlay guiding the user to frame the QR code - Provide haptic feedback on successful decode - Display the decoded content with a confirmation action (do not auto-navigate) - Handle the "no QR code found" state gracefully
QR display UX: - Generate at sufficient size (minimum 200x200 points) - Adjust brightness to maximum when displaying a QR code for scanning - Provide a "share" action to send the QR code image
Key Takeaways
- iOS Vision framework provides native scanning without dependencies
- iOS Core Image generates QR codes through CIQRCodeGenerator filter
- Android ML Kit is the recommended scanning library
- Always show decoded content before acting (no auto-navigation)
- Maximise screen brightness when displaying QR codes for scanning
Preguntas Frecuentes
Does a mobile app need a third-party QR library?
Not for the common cases. iOS covers scanning through the Vision framework and generation through the Core Image CIQRCodeGenerator filter, and Android covers scanning through ML Kit's BarcodeScanning client. All three ship with the platform, which keeps them out of the dependency tree and under vendor performance tuning.
How does an iOS app isolate QR results from other barcode types?
VNDetectBarcodesRequest returns a VNBarcodeObservation for every symbology it recognises. Testing each observation's symbology property against .qr narrows the results to QR codes, and payloadStringValue then yields the decoded string.
Can the error correction level be set when generating on iOS?
Yes. The Core Image filter takes it through the inputCorrectionLevel key as a single letter, so a symbol destined for print can be raised above the default before the resulting CIImage is rendered.