1. 下載SDK https://github.com/bmorton/ZBarSDK
2. 引用到專案中
3. 新增引用
4. AppDelegate中新增下面程式碼
5. 在需要使用掃描的controller中實現ZBarReaderViewDelegate
6. 對應的m檔案中
#import "ViewController.h" @interface ViewController () { UITextField *resultText; ZBarReaderView *readerView; ZBarCameraSimulator *cameraSim; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. resultText = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 200, 60)]; resultText.backgroundColor = [UIColor blueColor]; [self.view addSubview:resultText]; readerView = [[ZBarReaderView alloc]init]; readerView.frame = CGRectMake(10, 110, 300, 300); readerView.readerDelegate = self; //關閉閃光燈 readerView.torchMode = 0; //處理模擬器 if (TARGET_IPHONE_SIMULATOR) { ZBarCameraSimulator *cameraSimulator = [[ZBarCameraSimulator alloc]initWithViewController:self]; cameraSimulator.readerView = readerView; } [self.view addSubview:readerView]; [readerView start]; } - (void) readerView: (ZBarReaderView*) view didReadSymbols: (ZBarSymbolSet*) syms fromImage: (UIImage*) img { // do something useful with results for(ZBarSymbol *sym in syms) { resultText.text = sym.data; break; } [readerView stop]; }