Skip to content

Instantly share code, notes, and snippets.

@nenadvulic
Created September 23, 2013 22:29
Show Gist options
  • Save nenadvulic/6677856 to your computer and use it in GitHub Desktop.
Save nenadvulic/6677856 to your computer and use it in GitHub Desktop.
AVCaptureMetaDataOutput Bar Code Reader iOS7
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
error:&error];
if (input) {
[session addInput:input];
} else {
NSLog(@"Error: %@", error);
}
AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[session addOutput:output];
[session startRunning];
#pragma mark - AVCaptureMetadataOutputObjectsDelegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputMetadataObjects:(NSArray *)metadataObjects
fromConnection:(AVCaptureConnection *)connection
{
NSString *QRCode = nil;
for (AVMetadataObject *metadata in metadataObjects) {
if ([metadata.type isEqualToString:AVMetadataObjectTypeQRCode]) {
// This will never happen; nobody has ever scanned a QR code... ever
QRCode = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
break;
}
}
NSLog(@"QR Code: %@", QRCode);
}
Format supports
AVMetadataObjectTypeUPCECode
AVMetadataObjectTypeCode39Code
AVMetadataObjectTypeCode39Mod43Code
AVMetadataObjectTypeEAN13Code
AVMetadataObjectTypeEAN8Code
AVMetadataObjectTypeCode93Code
AVMetadataObjectTypeCode128Code
AVMetadataObjectTypePDF417Code
AVMetadataObjectTypeQRCode
AVMetadataObjectTypeAztecCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment