在我的代码中,我初始化了ZBarReaderViewController以进行二维扫描。

我需要检测用户何时退出QR扫描过程而不扫描任何二维码。
当用户退出ZBarReaderViewController之后,我有什么方法可以知道用户何时退出该过程(通过单击视图中的“取消”按钮)并执行某些操作?

先感谢您。任何信息都非常感谢!

下面是我的代码,只需单击一个按钮即可触发qr扫描过程。

-(IBAction)nextBtn:(id)sender{

     NSLog(@"trigger QR CODE");

     if(!reader)
     {
         reader = [[ZBarReaderViewController alloc]init];
         reader.readerDelegate = self;
         reader.supportedOrientationsMask = ZBarOrientationMaskAll;

         ZBarImageScanner *scanner = reader.scanner;
            // TODO: (optional) additional reader configuration here

            // EXAMPLE: disable rarely used I2/5 to improve performance
         [scanner setSymbology: ZBAR_I25
                     config: ZBAR_CFG_ENABLE
                             to: 0];

         UIView * infoButton = [[[[[reader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3];

         [infoButton setHidden:YES];
     }

     // present and release the controller
     [self.view addSubview:spinner];
     [self.view setUserInteractionEnabled:NO];
     [spinner startAnimating];

     [self presentViewController:reader animated:YES completion:NULL];

}

这是我在用户扫描二维码时捕获二维码的方式。
- (void) imagePickerController: (UIImagePickerController*) imageReader
  didFinishPickingMediaWithInfo: (NSDictionary*) info
 {
     // ADD: get the decode results
     id<NSFastEnumeration> results =
     [info objectForKey: ZBarReaderControllerResults];
     ZBarSymbol *symbol = nil;
     for(symbol in results)
         // EXAMPLE: just grab the first barcode
         break;


     NSString *receiptData = [NSString stringWithFormat:@"%@@-!-@%@", amountLabel.text, receiptLabel.text];

     isClosed = YES;
     NSLog(@"Completion");
     [reader dismissViewControllerAnimated:YES completion:^{
         [self BPUpdateTokenCollection:receiptData qrData:symbol.data];
         [reader.readerView stop];
          for(UIView *subViews in reader.view.subviews)
             [subViews removeFromSuperview];
         [reader.view removeFromSuperview];
         reader.view = nil;
         reader = nil;

      }];
  }

最佳答案

尝试这个

@protocol ZBarReaderDelegate <UIImagePickerControllerDelegate>



ZBarReaderDelegate is nothing but UIImagePickerControllerDelegate

- (void) imagePickerControllerDidCancel: (UIImagePickerController*) picker{

    //Cancelled

    //Do your stuff here


}

09-10 07:35
查看更多