使用ZbarSDK實現掃描二維碼以及條碼功能(iOS)

來源:互聯網
上載者:User

標籤:

1. 從 http://zbar.sourceforge.net/iphone 下載最新版本的ZBar SDK。

2. 雙擊下載好的檔案。目前版本是:ZBarSDK-1.2.dmg。

3. 按提示將ZBarSDK拖拽到我們自己的項目中。   

 

4. 使用ZBarSDK,還需要匯入其他的framework。

 工程 -> target -> build phases -> Link Binary With Libraries -> 點擊+添加以下framework。

  1>.AVFoundation.framework

  2>.CoreMedia.framework

  3>.CoreVideo.framework

  4>.QuartzCore.framework

  5>.libiconv.dylib

5. 匯入標頭檔:#import "ZBarSDK.h"

6. 聲明支援代理協議:<ZBarReaderDelegate>

7. 書寫代碼:

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.        self.title = @"二維碼掃描";        UIImageView * imageView = [[UIImageView alloc] init];    [imageView setFrame:CGRectMake(300, 162, 424, 424)];    [self.view addSubview:imageView];    self.resultImage = imageView;        [self scan];}- (void)scan{
  // ZBarReaderViewController * reader = [[ZBarReaderViewController alloc] init]; reader.readerDelegate = self; reader.supportedOrientationsMask = ZBarOrientationMaskAll; ZBarImageScanner * scanner = reader.scanner; [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0]; [self presentViewController:reader animated:YES completion:nil];}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

   // 得到條碼結果
id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];    ZBarSymbol * symbol = nil;    for (symbol in results) {        break;    }

    // 列印條碼

    self.resultImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];        [picker dismissViewControllerAnimated:YES completion:nil];    

    // 退出掃描介面

    MyLog(@"result:%@", symbol.data);}

 

使用ZbarSDK實現掃描二維碼以及條碼功能(iOS)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.