jaamun
jaamun

Reputation: 181

Zxing Library for Iphone

Can I use the ZXing Library and scan a qr code in the background of my iphone app? I do not want the camera overlay with the square that looks for the qr code and the cancel button (as is shown in the ScanTest Example). What I need is that pressing the scan button will activate the reading of the QR code, and when the QR Code is read, how do I return the text to my application, so I can display it in a UILabel on the screen.

Can anyone show some example code in Objective-C for this? Thanks.

Upvotes: 0

Views: 1203

Answers (2)

smparkes
smparkes

Reputation: 14073

There are a set of classes in the zxing objc directory that operate at the CA level rather than the UIView level that might be easier to modify than the widget, which operates at the UIViewController level.

This would still take a little tweaking, though, because the core capture code tracks whether the view is on screen or not to automatically start and stop the capturing of frames.

Upvotes: 0

Dan Collins
Dan Collins

Reputation: 1018

I did something similar, and can provide you with some guidance, but can't share source code.

Take a look at ZXingWidgetController.mm,.h files. This is a fully functioning QRcode scanning app that you can compile, so it can be reverse engineered into just containing the backend code. Edit the .h so the class extends NSObject instead of UIViewController, then delete any class properties and instance variables that are GUI objects.

That will cause xcode to find and mark all the methods and variables that you no longer need with warnings/errors in the .mm file (willAppear, etc.). Most of this code can be deleted, but be mindful to move allocations/deallocations to constructors/deconstructors.

In the viewController you can create an instance of this class, and call the class to start scanning. You need to modify the didDecodeImage in the ZXingWidgetController.mm file to do what you want it to do when it successfully gets a result from the QR code. One possibility is to modify the constructor to take your parent view controller as a parameter, store it in an instance variable as a delegate (__weak), then use that to call one of its functions in the didDecodeImage method. Other people might pass the data back to your main code using notifications.

Hope this helps!

Upvotes: 1

Related Questions