我按照本教程在我的 iOS 应用程序中实现 zbarcode 阅读器。由于我使用的是自定义 UISegmentedControl,因此相机应在该段单击时立即启动并开始扫描 QR 码。相机正在启动,但缺少红线,因此无法扫描 QR 码。
我在提到的日志中收到此警告
Warning: Attempt to present <ZBarReaderViewController: 0x7befb50> on <UINavigationController: 0x7b6f950> while a presentation is in progress!
我在 ScanViewController 段的 viewWill 加载中编写了按钮逻辑。使用 Xcode 4.6 并在 iPad 2 中进行测试。这是我的代码
- (void) imagePickerController: (UIImagePickerController*) reader 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;
// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;
// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"Starting Camera to scan QR Code...");
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
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];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
NSString *checkURL = self.resultText.text;
NSLog(@"Checking URL scanned from QR Code before passing to List :: %@", checkURL);