尝试使用ZBar捕获条形码。我现在有以下代码。当代码周围出现绿色覆盖时,扫描仪显示并显示扫描条形码。我不知道如何捕获解码结果。
我可能会犯错,所以我想问一下。扫描时没有任何内容输出到控制台,所以不要认为根本没有调用didReadSymbols。
·H
@interface ScannerViewController : UIViewController <ZBarReaderDelegate> {
}
@property (strong, nonatomic) IBOutlet UILabel *readerResult;
@property (strong, nonatomic) IBOutlet UIView *readerView;
@property (strong, nonatomic) IBOutlet ZBarReaderView *zbr;
的.m
- (void)viewDidLoad
{
[super viewDidLoad];
// force class to load so it may be referenced directly from nib
[ZBarReaderViewController class];
ZBarReaderViewController *reader= [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
//reader.cameraOverlayView = self.readerView;
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 1];
[reader setShowsZBarControls:NO];
[reader.readerView start];
self.zbr = reader.readerView;
[self.view addSubview:reader.view];
}
- (void) zbr: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
NSLog(@"Scanner used");
//do something useful with results and display resultText in resultViewController
for(ZBarSymbol *sym in syms) {
NSLog(@"Logged");
//return resultText;
break;
}
}
任何建议都会很棒。我此刻对此非常困惑。干杯。
答案 0 :(得分:0)
当我查看ZBar的文档时,I see the delegate method signature is:
- (void) readerView:(ZBarReaderView*)readerView didReadSymbols:(ZBarSymbolSet*)symbols fromImage:(UIImage*)image
这与上面的内容不同。将“zbr
”替换为“readerView
”,您的委托方法应该被调用。
答案 1 :(得分:0)
我将以下内容添加到ScannerViewController界面。
ZBarReaderViewController *reader;
然后我更改了下面的readerView方法,它完美无缺。
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
UIImage *image =
[info objectForKey: UIImagePickerControllerOriginalImage];
NSString *resultText = [[NSString alloc] init];
for(ZBarSymbol *sym in results) {
NSLog(@"%@", sym.data);
resultText = sym.data;
//return resultText;
break;
}
}