Warning: ob_start(): non-static method sem_google_analytics::track_links() should not be called statically in /home/osanderson/oscarsanderson.com/wp-content/plugins/sem-google-analytics/sem-google-analytics.php on line 178

Implementing a QR Code reader on the iPhone

QRCode OscarSanderson.com

QR Codes are becoming increasingly popular but few people realize just how easy it is to support this technology from an iPhone application.

In this example, I’ll illustrate how to knock together a simple QR Code reader using the open source ZBarSDK. It’s not going to be an ‘All singing, all dancing’ application, but it will be sufficient to illustrate the point.

The following example assumes that you’re already familiar with both XCode and iPhone development.

Step 1: Create a Window-based iPhone application and name it ‘QRReader’

Step 2: Download ZBarSDK

Step 3: Run the ZBarSDK installer and follow the simple instructions for adding the SDK to your XCode project

Step 4: Add the following frameworks to your project:

  • QuartzCore.framework
  • AVFoundation.framework
  • libiconv.dylib
  • CoreVideo.framework
  • CoreMedia.framework
  • AudioToolbox.framework

Step 5: Add the main view to the Application Delegate, as follows:

AppDelegate #1

AppDelegate #2

At this point ZBarSDK is already integrated with the video feed from the camera, but we still need to implement the delegate so that the SDK can notify us when it has managed to detect a QR Code.

The following delegate method should now be added to the Application Delegate:

Step 6: Next we need to create a new UIViewController subclass and call it ‘QRCodeDetail’. This will be used to show the details of the QR Code once it has been read by the main view.

Update the header file to contain the following:

QRCodeDetail #1

Remember to synthesize the variables:

QRCodeDetail #2

Finally we update the ‘viewDidLoad’ method:

QRCodeDetail #3

Step 7: Hook the QRCodeDetail view into the main view

Back in the Application Delegate we need to import our newly created view:

AppDelegate #4

Then we need to update the ‘didFinishPickingMediaWithInfo’ method to load the ‘QRCodeDetail’ view whenever a QR Code is detected:

AppDelegate #5

Step 8: Simply install on an iPhone and enjoy the QR Code Reader.

You can easily generate your own QR Codes here.


  1. Baci says:

    Hi, Oscar. Can one run this on the simulator? Can one feed it sample QR codes via a list of .png files? If so, what code should be added please? I’m a newbie in XCode world. Am using XCode 3.2 Simulator 4.1. Hope you can help. Thanks in advance.

Leave a Reply to Oscar