我需要在应用程序中集成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];
}
所有必要的框架都已添加,因此不会出现“引用自”错误。
当我点击扫描按钮时,ZBarReaderViewController正常显示,我按住alt键并左键单击鼠标以打开模拟器的照片库,一切都正常。
问题在于:
- QR图像未被扫描,即
imagePickerController:(UIImagePickerController*) reader didFinishPickingMediaWithInfo
函数未被调用。 - QR图像显示比其原始大小大。
如何解决这个问题?
为什么图像没有被扫描?