QR code reader for iPhone

前端 未结 4 1649
太阳男子
太阳男子 2020-12-12 11:51

I want to create QR code reader based application.

Using which library, I can create my application ?

Note: I searched in google. Always I am getting

4条回答
  •  伪装坚强ぢ
    2020-12-12 12:13

    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);
       }
    

    AVFoundation supports every code you've heard of (and probably a few that you haven't):

    AVMetadataObjectTypeUPCECode
    AVMetadataObjectTypeCode39Code
    AVMetadataObjectTypeCode39Mod43Code
    AVMetadataObjectTypeEAN13Code
    AVMetadataObjectTypeEAN8Code
    AVMetadataObjectTypeCode93Code
    AVMetadataObjectTypeCode128Code
    AVMetadataObjectTypePDF417Code
    AVMetadataObjectTypeQRCode
    AVMetadataObjectTypeAztecCode
    

提交回复
热议问题