アプリにQRコードリーダーを統合する必要があり、チュートリアルそれのための。
私はここからZ-bar SDKをダウンロードしましたリンク。
私がやったことは次のとおりです。
QRscannerViewController.m内
-(IBAction)StartScan:(id) sender
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.readerView.torchMode = 0;
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];
[reader release];
resultTextView.hidden=NO;
}
- (void) readerControllerDidFailToRead: (ZBarReaderController*) reader
withRetry: (BOOL) retry{
NSLog(@"the image picker failing to read");
}
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
NSLog(@"the image picker is calling successfully %@",info);
// ADD: get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
NSString *hiddenData;
for(symbol in results)
hiddenData=[NSString stringWithString:symbol.data];
NSLog(@"the symbols is the following %@",symbol.data);
// EXAMPLE: just grab the first barcode
// break;
// EXAMPLE: do something useful with the barcode data
//resultText.text = symbol.data;
resultTextView.text=symbol.data;
NSLog(@"BARCODE= %@",symbol.data);
NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
[storeData setObject:hiddenData forKey:@"CONSUMERID"];
NSLog(@"SYMBOL : %@",hiddenData);
resultTextView.text=hiddenData;
[reader dismissModalViewControllerAnimated: NO];
}
必要なフレームワークはすべて追加されたので、エラーはありませんreferenced from
。
スキャン ボタンをクリックすると、ZBarReaderViewController が正しく表示され、Alt キーを押しながらマウスを左クリックしてシミュレータの写真ライブラリを開くと、すべて正常に動作します。
何が問題なのか、
- QR 画像はスキャンされません。つまり、
imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo
関数は呼び出されません。 - QR 画像は元のサイズよりも大きく表示されます。
これをどうやって解決すればいいでしょうか?
なぜ画像がスキャンされないのですか?
ベストアンサー1
のリリースにより、iOS7
外部フレームワークやライブラリを使用する必要がなくなりました。AVFoundationを搭載したiOSエコシステムは、スキャンを完全にサポートするようになりましたQR から EAN、UPC まで、ほぼすべてのコード。
ちょっと見てください技術ノートそしてそのAVFoundation プログラミング ガイド。AVMetadataObjectTypeQRCode
あなたの友だちです。
ここに素敵なチュートリアルそれを段階的に示します:iPhone QRコードスキャンライブラリ iOS7
設定方法の簡単な例:
#pragma mark -
#pragma mark AVFoundationScanSetup
- (void) setupScanner
{
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];
self.session = [[AVCaptureSession alloc] init];
self.output = [[AVCaptureMetadataOutput alloc] init];
[self.session addOutput:self.output];
[self.session addInput:self.input];
[self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.preview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
AVCaptureConnection *con = self.preview.connection;
con.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
[self.view.layer insertSublayer:self.preview atIndex:0];
[self.session startRunning];
}