Chapter 1. Barcodes, iOS, and you
This chapter covers
- Why the nexus of barcodes and mobile technologies is creating new, exciting opportunities for app makers
- The barcode symbologies in iOS you should know about
- The distinctions between 1D and 2D barcodes
- A brief history of the UPC/GTIN, the mother of modern barcodes
In the past, if you wanted to add barcode scanning to your apps, you had to either fight your way through open source projects or license a commercial barcode-scanning library. None of those projects were written in Objective-C, documentation was lacking, and commercial solutions required payment of license fees for each downloaded copy of your app. All of these issues made barcode scanning impractical for all but the most skilled iOS developers, and too expensive to make economic sense for free or low-cost apps.
When Apple added Passbook to iOS 6, they built in the ability to display barcodes on Passbook passes. With iOS 7, Apple made these APIs public and added the ability to scan barcodes. This allowed them to add barcode-scanning functionality to several of their first-party apps:
- The Passbook app lets you add new passes to your device by scanning special QR Codes.
- The iTunes app has the ability to redeem iTunes credits by scanning a voucher.
- The Apple Store app has an in-store UI that lets you scan the barcodes of accessories for unassisted checkout (see figure 1.1).
Figure 1.1. Barcode scanning in the Apple Store app
In June 2014, the mother of all barcodes, the UPC, celebrated its 40th anniversary. This makes it an incredibly well understood and ubiquitous technology. Throughout these four decades, different usage scenarios prompted the development of a variety of barcode symbologies that were more or less all informed by the UPC. Apple selected from these the most prevalent and useful kinds of barcodes to support in iOS 7. Support for a few additional barcode symbologies was added in iOS 8. To grasp the full potential of these differing symbologiesâas theyâre relevant to you in iOS app developmentâyouâll learn which purposes theyâre best used for.
This introductory chapter will give you a solid understanding of barcode technology. Seeing how the multitude of symbologies relate to each other should alleviate any anxiety you might feel right now. Youâll no longer shiver in fear from not knowing the difference between UPC, EAN, GTIN, Code 25, Code 39, Code 93, and Code 128. A brief history of the UPC/GTIN will prove illuminating. Not only has its long history been quite amusing at times, this background will aid greatly in your appreciation of the current state of the GTIN. Youâll become a barcode guru and be able to hold your own in any discussion about barcodes.
In order to appreciate the power of the barcode, weâll first take a look at how they evolved. Beginning with the UPC, more and more barcode symbologies evolved over time because their predecessors had been designed to solve very specific problems. If you know how to tell them apartâjust from glancing at themâyouâll know if youâre looking at an opportunity for a new app.
1.1. The evolution of barcodes
The first barcode in wide use was the Universal Product Code (UPC), combining the semantic meaning of a 12-digit number with a machine-readable scheme for representing this number as a series of bars. It was designed only for automated handling of physical products and was therefore limited to representing numerical product codes. Appendix A will walk you through the history of the UPC and how it became the GTIN, as itâs referred to nowadays by people in the know. Figures 1.2a and 1.2b show some examples of how barcodes have changed over the years.
Figure 1.2a. Timeline of barcodes
Figure 1.2b. Timeline of barcodes
Having overcome the hurdle of enabling a machine to recognize visual markings with a laser beam, a plethora of other kinds of barcodes started to appear, all with more-or-less specific fields of application. For example, the post office found that adding markings to mailed items would allow them to automatically sort the items. Luggage for airline travel was similarly tracked with numeric codes. Other industries had their own standards that worked better for them.
A combination of several bars that make up an individual character or digit is often called a symbol. The set of symbols available for a specific barcode standard is referred to as its symbology. All these different symbologies can be read with a laser beam.
1.1.1. One dimension: laser
Think of a laser beam as cutting out a horizontal slice of the vertical code bars. As the beam moves over the symbol (see figure 1.3), it measures the relative time it spends scanning dark bars and light spaces. A lookup table is then used to decode individual characters from those times.
Figure 1.3. A laser needs to cross all bars of a 1D barcode for scanning
The line of the laser beam is also the reason why these kinds of barcodes are referred to as being one-dimensional (1D).
If you have more-complex encoding schemes, you can also represent letters and special characters. Some 1D barcode types were created to represent short texts.
The long-recognized major advantage of 1D barcodes is that they can be decoded extremely reliably even when the items tagged with such codes are moving at high speed. Some schemes even employ checksums to recognize when something is misread and increase this reliability.
The second advantage of 1D barcodes is cost. Because the technology has been around for 40 years now, the necessary components (laser diode and decoding electronics) have become cheap and reliable. This makes them ideally suited for high-volume deployment as well as for use in environments where you need to scan a great many codes in quick succession.
1.1.2. Two dimensions: CCD
The charge-coupled device (CCD) was invented at AT&T Bell Labs by Willard Boyle and George E. Smith in 1969. This is the chip at the heart of any kind of digital camera. Curiously, the technology for CCDs was invented around the time the first 1D barcode was introduced, but it took decades to develop CCDs to the point where they could compete with the accuracy of their technically much simpler predecessors.
A CCD is essentially a matrix of pixels that reads different binary values for each pixel depending on the light intensity shining on it. As a result, a CCD can read barcodes just like a laser beam can if you have a sufficient number of pixels (a.k.a. resolution). Because the CCD pixels are laid out in two dimensions, CCDs are also able to recognize a new kind of barcode, the two-dimensional (2D) barcode.
Freed of the limitations of one dimension, 2D barcodes usually consist of small rectangles laid out to form a square grid. Figure 1.4 shows such a barcode.
Figure 1.4. A CCD camera can âseeâ the squares that make up a 2D b...