iOS 应用里实现条形码扫描功能,有个免费开源的 SDK:ZBar(
http://zbar.sourceforge.net/iphone/sdkdoc/install.html)下面是实现的效果:
利用条形码,可以简单的得到二维码的值。具体的实现过程如下:
- 下载 ZBar 的 SDK
- 创建工程,iphone.scanbar
- 把下载的 ZBarSDK 添加到工程中
- 添加 .framework 到工程中
- 添加一个按钮,处理效果。
#pragma mark –
#pragma mark onClickButton
-(IBAction)onButton:(id)sender
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self presentModalViewController: reader
animated: YES];
[reader release];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
NSLog(@"===%@",symbol.data);
resultText.text = symbol.data;
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
[reader dismissModalViewControllerAnimated: YES];
}
源代码:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.scanbar/