作者:手机用户2502880437 | 来源:互联网 | 2023-10-12 15:27
1、去下载SDK:http:zbar.sourceforge.netiphoneindex.html。2、新建你的IOSProject。3、导入ZbarSDK
1、 去下载SDK:
http://zbar.sourceforge.net/iphone/index.html
。 2、新建你的IOS Project。 3、导入ZbarSDK,直接拖动你下载的ZbarSDK到你的项目,并且选择copy选项。 4、添加如下framework 5、在appDelegate文件的以下方法中加入如下: - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- //your code
- [ZBarReaderView class];
- return YES;
- }
6、在你需要使用扫描功能的ViewController.h文件添加如下: - #import
- #import "ZBarSDK.h"
- @interface ScanViewController : UIViewController
- {
- ZBarReaderView *readerView;
- ZBarCameraSimulator *cameraSim;
- }
- @property (retain, nonatomic) IBOutlet ZBarReaderView *readerView;
- @end
7、在你需要使用扫描功能的ViewController.m文件添加如下: - #import "ScanViewController.h"
- @interface ScanViewController ()
- @end
- @implementation ScanViewController
- @synthesize readerView;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- //your code
- readerView.readerDelegate = self;
- [readerView setAllowsPinchZoom:YES];
- if (TARGET_IPHONE_SIMULATOR) {
- cameraSim = [[ZBarCameraSimulator alloc] initWithViewController:self];
- cameraSim.readerView = readerView;
- }
- }
- -(void)viewDidAppear:(BOOL)animated
- {
- [readerView start];
- }
- -(void)viewDidDisappear:(BOOL)animated
- {
- [readerView stop];
- }
-
- -(void) readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
- {
- NSString *codeData = [[NSString alloc] init];;
- for (ZBarSymbol *sym in symbols) {
- codeData = sym.data;
- break;
- }
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"掃描結果" message:codeData delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- [alert show];
- }
-
- -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
- {
- // 得到条形码结果
- id results =
- [info objectForKey: ZBarReaderControllerResults];
- ZBarSymbol *symbol = nil;
- for(symbol in results)
- break;
- //获得到条形码
- //NSString *dataNum=symbol.data;
- //扫描界面退出
- [picker dismissModalViewControllerAnimated: YES];
- }
-
8、至于需要如何美化你的扫描界面或者其他的使用方式,将在以后的帖子中继续探讨。 9、最终界面上一张粗糙的模拟器截图: