适用于iPhone的QR码阅读器

jfa*_*jay 43 iphone qr-code zxing

我想创建基于QR码阅读器的应用程序.

使用哪个库,我可以创建我的应用程序?

注意:我在谷歌搜索.我总是得到zxing.我下载了zxing项目.但问题是; 我运行应用程序.但它只读取条形码.没有选择读取QR码.

请告诉我怎么做...

提前致谢.

Mar*_*off 49

ZBarSDK是另一种选择.一个非常有能力的库.

更新 2014年1月

从iOS7开始,AVCaptureDevice现在包括读取条形码(各种条形码)并返回人类可读值的功能.如果你的目标是iOS7 +,那么这就是你要走的路.当然,ZBarSDK仍然非常适合iOS7之前的支持.


iGo*_*iGo 28

AVCaptureMetaDataOutput - Starting from iOS 7

Scan UPCs, QR codes, and barcodes of all varieties with AVCaptureMetaDataOutput, new to iOS 7. All you need to do is set it up as the output of an AVCaptureSession, and implement the captureOutput:didOutputMetadataObjects:fromConnection: method accordingly:

 @import AVFoundation;

 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 setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];
 [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);
   }
Run Code Online (Sandbox Code Playgroud)

AVFoundation 支持你听过的每一个代码(可能还有一些你没有的代码):

AVMetadataObjectTypeUPCECode
AVMetadataObjectTypeCode39Code
AVMetadataObjectTypeCode39Mod43Code
AVMetadataObjectTypeEAN13Code
AVMetadataObjectTypeEAN8Code
AVMetadataObjectTypeCode93Code
AVMetadataObjectTypeCode128Code
AVMetadataObjectTypePDF417Code
AVMetadataObjectTypeQRCode
AVMetadataObjectTypeAztecCode
Run Code Online (Sandbox Code Playgroud)

  • `[session addOutput:]`方法必须在`[output setMetadataObjectTypes:@AVMetadataObjectTypeQRCode]];`之前调用.否则你将得到一个NSInvalidArgumentException. (7认同)
  • 有关更方便处理方向更改,从后台恢复等内容的更完整示例,请参阅https://github.com/magmatic/BMCodeScanner - 使用本机AVFoundation API. (4认同)
  • 我希望我能两次+1.一次用于代码,另一次用于`@ import`. (2认同)