このチュートリアルに従って、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);