I'm finding older questions and answers on this topic. But I gather in iOS 7 there is a framework for QR codes. Does it support barcodes too? And if I want to support earlier devices, what is the library that is considered the best as of now?
The QR code might not be scanned due to any of the following reasons: The OS version of the device is not iOS 11 or above. QR scanning is disabled in the camera app. The QR is not detected more than once.
If you own an iPhone with iOS 11 and above, you do not need to download a separate app to scan a QR Code.
iOS 7 introduced QR code and Barcode reading support in AVCaptureMetadataOutput
. It can read the following formats:
To implement it you need to add an AVCaptureMetadataOutput
with the object types you want to scan for to an AVCaptureSession
.
AVCaptureMetadataOutput *metadataOutput= [[AVCaptureMetadataOutput alloc] init];
[self.session addOutput:metadataOutput];
[metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[metadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeCode128Code]];
And implement the following delegate method:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
The different metadata objects you can listen for are listed here: https://developer.apple.com/library/ios/DOCUMENTATION/AVFoundation/Reference/AVMetadataMachineReadableCodeObject_Class/Reference/Reference.html
A popular library for previous versions of iOS was ZBar although I know a lot of users had issues with ZBar when trying to use it with iOS 7. This may have been fixed by now though.
http://zbar.sourceforge.net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With