您的位置:首页 > 移动开发 > IOS开发

IOS 开发学习七 二维码扫描功能(ZBar SDK)

2015-04-29 16:11 281 查看
1.下载:

点击打开链接

2.拖动下载的sdk到项目里,选择 copy

3.添加framework

* AVFoundation.framework (weak)
* CoreMedia.framework (weak)
* CoreVideo.framework (weak)
* QuartzCore.framework
* libiconv.dylib




完整的文档在Documentation.html里。

4.如果编译有如下错误:

"_OBJC_CLASS_$_ZBarReaderViewController", referenced from ...

则到Targets设置:



4.在Controller.h里加代码:

#import <UIKit/UIKit.h>

@interface ReaderSampleViewController : UIViewController
{

}
@property (weak, nonatomic) IBOutlet UIImageView *resultImage;

@property (weak, nonatomic) IBOutlet UILabel *resultText;

- (IBAction) scanButtonTapped;
@end


在Controller.m里加代码:

#import "ReaderSampleViewController.h"
#import "ZBarSDK.h"

@interface ReaderSampleViewController ()
{

}

@end

@implementation ReaderSampleViewController

@synthesize resultImage,resultText;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)scanButtonTapped{
NSLog(@"Barcode scan ");
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];
//[reader release];
}
- (void) dealloc{
self.resultText=nil;
self.resultImage=nil;
//[super dealloc];
}
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return true;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (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];
}
@end



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: