我按照这个tutorial在我的iOS应用程序中实现了zbarcode reader。由于我使用的是自定义UISegmentedControl,因此摄像机应立即启动该段点击并开始扫描QR码。相机正在启动,但缺少红线,因此无法扫描QR码。
我在提及
的日志中收到此警告Warning: Attempt to present <ZBarReaderViewController: 0x7befb50> on <UINavigationController: 0x7b6f950> while a presentation is in progress!
我在viewWill加载ScanViewController段时编写了按钮逻辑。 使用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);
答案 0 :(得分:0)
将代码移至
- (void) viewDidAppear:(BOOL) animate { }
而不是viewWillAppear。
问题是你在视图出现之前尝试使用mallodViewController。