Using the iOS7 BarCode Scanner - Book App (Xamarin.iOS-Monotouch)

Darrell Kress / Friday, October 11, 2013


So Torrey B. here at Infragistics wrote a sample app showing off the bar code scanning capabilities in iOS7 .  After the obligatory showing off around our desks, I thought of something that I wanted to do for a while now, but didn’t have the time for.  That and I didn’t have a handy barcode scanner in my possession.

I used to read a lot of pulp, serialized fiction, before I got way to busy.  The kind where titles and cover art seem to blend together and anthologies get put together but I already have the three books that make it up.  I also prefer to go to bookstores and wander around rather than order it all online.    So I wanted to put together something that would allow me to scan through my collection and record what I already own.  


For this project I used Xamarin Studio, so the code will be in C# but it should be easy enough to convert to an Objective C version later.


Building off Torrey’s sample, I modified the AVCaptureMetadataOutputObjectsDelegate so that instead of just writing the ISBN to the screen, it also sends out a request to to retrieve the book cover for the book.  

// Uses open library
string baseURL = _parentViewController.IsIPhone ? @"{0}-S.jpg" :@"{0}-M.jpg";

string address = string.Format (baseURL, detectionString);
CoverUrlConnectionDelegate del = new CoverUrlConnectionDelegate (_parentViewController);

NSUrlRequest request = new NSUrlRequest (new NSUrl (address));

NSUrlConnection conn = new NSUrlConnection (request, del);

When the request comes back through the delegate, we process the data into an jpg and then through a convenient link back up the the ViewController, update a UIImageViewer to display the found cover.

public override void FinishedLoading (NSUrlConnection connection)
	UIImage img = new UIImage (_responseData);
	_parentViewController.ImageViewer.Image = img;
	_parentViewController.PendingRequest = false;

Short and sweet.

Ultimately my goal is to write an app that allows me to record all the books scattered across my bookshelves, persist them (probably in the cloud) so that my other devices can load my library when I decide to go searching for my next book, and since I am a stat geek, allow me to chart and graph my collection in fun ways (fun for me at least).


 So my backlog is:

-       Better underlying object model

-       A persistence model, local at first, cloud in the end

-       Bibliometrics, it’s like sabermetrics, but for books.

-       Lunch

-       Better UI for displaying collection (goes along with the object model and persistence)’


I think I will start with object model and persistence.  So next time we should be able to record books into the system,  recall from the system if we scan the same book again, and maybe throw up some sort of notification if the book was fetched from the local store.

Articles in this series

1) Using the iOS7 BarCode Scanner - Book App (Xamarin.iOS-Monotouch)

2) Book App – Persisting with NSCoding and Introducing IGGridView (Xamarin.iOS-Monotouch)

By Darrell Kress