In iOS 7 apple introduced support for reading MachineReadable Code(Barcodes). As of today it supports these machine formats for reading. Frameworks also provide core images filters to generate these barcodes. In this post we will implement the same for iOS 8 and Swift.
This is how the final example will work.
To implement barcode scanning in our app we need to have some idea about how AVFoundation works.
AVCaptureSession is one of the key object that will help in managing the data flow from the capture stage through our input devices like camera/mic to output like a movie file. We can also provide custom presets which will control the quality/bitrate of the output.
An AVCaptureDevice object represents a physical capture device and the properties associated with that device. You use a capture device to configure the properties of the underlying hardware. A capture device also provides input data (such as audio or video) to an AVCaptureSession object. We also have the flexibility to set the properties on the input device like (focus, exposure etc) but the should be done while having a lock on that particular device object
AVCaptureInputDevice is useful for capturing the data from the input device.
AVCaptureVideoPreviewLayer is special CGlayer which will help us display the data as captured from our input device
Here is the flow on how the start capturing input from the device.