2016-12-20 3 views
-1

Я хочу использовать библиотеку QR-ридера в своем приложении ios. Какая лучшая библиотека для чтения QR-кода для IOS? Я нашел некоторых в github, но не уверен, что это нормально или нет.Какая лучшая библиотека для чтения QR-кода для IOS?

+0

проверить https: //www.appcoda. com/qr-code-reader-swift/ – Amanpreet

+0

zBar наиболее часто используется в библиотеке. Если ваши возможности ограничены, перейдите с помощью встроенной камеры для сканирования qr –

ответ

1

IOS уже QR-ридер реализован в AVFoundation с прошивкой 7 here is a tutorial о том, как реализовать

3

попробовать это на ios7 и новее

Захватить QR-код:

- (IBAction)Capture:(id)sender { 

    isFirst=true; 
_session = [[AVCaptureSession alloc] init]; 
    _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    NSError *error = nil; 

    _input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error]; 
    if (_input) { 
     [_session addInput:_input]; 
    } else { 
     NSLog(@"Error: %@", error); 
    } 

    _output = [[AVCaptureMetadataOutput alloc] init]; 
    [_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; 
    [_session addOutput:_output]; 

    _output.metadataObjectTypes = [_output availableMetadataObjectTypes]; 

    _prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session]; 
    _prevLayer.frame = self.view.bounds; 
    _prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    [self.view.layer addSublayer:_prevLayer]; 

    [_session startRunning]; 
} 

Для чтения используйте его делегатский метод:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection 
{ 
    CGRect highlightViewRect = CGRectZero; 
    AVMetadataMachineReadableCodeObject *barCodeObject; 
    NSString *detectionString = nil; 
    NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, 
      AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code, 
      AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]; 

    for (AVMetadataObject *metadata in metadataObjects) { 
     for (NSString *type in barCodeTypes) { 
      if ([metadata.type isEqualToString:type]) 
      { 
       barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata]; 
       highlightViewRect = barCodeObject.bounds; 
       detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue]; 
       break; 
      } 
     } 

     if (detectionString != nil) 
     { 
      if (isFirst) { 
      isFirst=false; 
      _label.text = detectionString; 
      break; 
      } 
     } 
     else 
      _label.text = @"(none)"; 
    } 

    _highlightView.frame = highlightViewRect; 
} 
Смежные вопросы