Scanning QR code with color gradient

Some businesses are printing QR codes that have color gradients. My App using the native QR scan library but I can only seem to scan black and white QR codes. When scanning a QR code with Apple's camera app, it has no problem scanning the QR code that has a color gradient. But my app cannot scan the same QR code. Please advise on what line of code I need to add in order to recognize color gradient QR codes.

Replies

I forgot to mention the current code

  • (void)setupNativeScanner

{    AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];    self.session = captureSession;    AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];    self.device = captureDevice;    NSError *error = nil;        self.input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];    if (self.input)        [_session addInput:_input];    else        NSLog(@"Error: %@", error);        AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];    [captureSession addOutput:captureMetadataOutput];    self.output = captureMetadataOutput;        dispatch_queue_t dispatchQueue;    dispatchQueue = dispatch_queue_create("myQueue", NULL);    [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];    [captureMetadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code,                                                    AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code,                                                    AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]];         //   [self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; //   [captureSession addOutput:_output];        self.output.metadataObjectTypes = [self.output availableMetadataObjectTypes];        self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.session];    self.prevLayer.frame = self.view.bounds;    self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;    [self.view.layer addSublayer:self.prevLayer];        [self.session startRunning];        [self.view bringSubviewToFront:self.highlightView]; }

  • (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects

      fromConnection:(AVCaptureConnection *)connection {    connection.enabled = NO;    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)    {        NSLog(@"metadata type %@", [metadata type]);        if ([metadata respondsToSelector:@selector(stringValue)])            NSLog(@"metadata string %@", [(AVMetadataMachineReadableCodeObject *)metadata stringValue]);        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)        {            [self.nativeScannerDelegate didFoundCode:metadata.type result:detectionString];            break;        }    }        [self performSelector:@selector(closeWithoutAnimation) withObject:nil afterDelay:0.1];    self.highlightView.frame = highlightViewRect; }

You should better use the Code Block feature properly.

Even someone eager to help found this thread, they would not try to go further given this sort of unformatted code.