#Robocop
The fairest, smartest and easiest way to read all kinds of AVMetadataObjectType objects like EAN13, QR Code, Aztec Codes and even face detection, among others barcodes with just one method call for iOS 7+ devices.
By default, Robocop is setup to read QR codes out-of-the-box.
##Installation
- The preferred way of installation is via Cocoapods. Just add
pod 'Robocop'
to your Podfile and run pod install
. It will install the most recent version of Robocop.
Alternatively you could copy all the files in the Classes/
directory into your project. Be sure 'Copy items to destination group's folder' is checked.
##Best Features ###Blocks!! ####Code Reader Handler
typedef void (^RobocopCodeReaderHandler)(NSString *machineCodeString);
You get this callback along with the string representation of the read code.
####Rect of Interest Handler
typedef void (^RobocopRectOfInterestHandler)(CGRect rectOfInterest);
You get this callback with the CGRect
representing the bounding rectangle of the object with respect to the picture in which the barcode/face resides.
##Basic Usage
- Import the header:
#import "Robocop.h"
- Setup QR Reader and Start reading:
[[Robocop sharedInstance]
startReadingInView:self.view
readerHandler:^(NSString *machineCodeString) {
NSLog(@"Code: %@", machineCodeString);
} rectOfInterestHandler:^(CGRect rectOfInterest) {
// The rect for the barcode being read
// See code example to know how to add a highlight layer using this rect on top of your preview
NSLog(@"%@", NSStringFromCGRect(rectOfInterest));
}];
- That's all!
##Screenshots
##Available Methods ###How to read other kinds of machine codes (including face detection)
- (void)startReadingMachineReadableCodeObjects:(NSArray *)codeObjects
inView:(UIView *)preview
readerHandler:(DHCodeReaderHandler)readerHandler
rectOfInterestHandler:(DHReaderRectOfInterestHandler)rectOfIntesetHandler;
Use this method to pass an array containing the AVMetadataObjectType objects that you want the reader to be able to distinguish.
For example:
NSArray *codeTypes = @[AVMetadataObjectTypeFace, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeQRCode];
And here is how you use the method with the array above mentioned:
[[Robocop sharedInstance]
startReadingMachineReadableCodeObjects:codeTypes
inView:self.view
readerHandler:^(NSString *machineCodeString) {
NSLog(@"Code: %@", machineCodeString);
} rectOfInterestHandler:^(CGRect rectOfInterest) {
NSLog(@"%@", NSStringFromCGRect(rectOfInterest));
}];
All the code types that you can read are declared on AVFoundation/AVMetadataObject.h
If you want to detect all kind of codes just pass nil to the method above for the codeObjects array.
[[Robocop sharedInstance]
startReadingMachineReadableCodeObjects:nil
inView:self.view
readerHandler:^(NSString *machineCodeString) {
NSLog(@"Code: %@", machineCodeString);
} rectOfInterestHandler:^(CGRect rectOfInterest) {
NSLog(@"%@", NSStringFromCGRect(rectOfInterest));
}];
- (void)stop;
Simple enough, isn't it?
##Contribution
Of course, please send a pull-request and/or raise an issue. It is always good to know how to make things better, yay!
##Author
David Hernandez ([email protected])
##License
Robocop is under the MIT License.