在我的代码中,我初始化ZBarReaderViewController
进行qr扫描。
我需要检测用户何时退出 QR扫描进程而不扫描任何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];
}
这是我在用户扫描时捕获qr代码的方法。
- (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;
}];
}
答案 0 :(得分:1)
试试这个
@protocol ZBarReaderDelegate <UIImagePickerControllerDelegate>
ZBarReaderDelegate is nothing but UIImagePickerControllerDelegate
- (void) imagePickerControllerDidCancel: (UIImagePickerController*) picker{
//Cancelled
//Do your stuff here
}