ios上ZXing庫的配置流程

來源:互聯網
上載者:User

標籤:c   class   blog   code   tar   http   

 

本文轉載至 http://blog.csdn.net/louercab/article/details/26448587

步驟

        首先,用Xcode建立我們的demo, 取名TestZXing(根據自己的喜好隨便取)。找到項目的位置,開啟檔案夾,在裡面建立一個檔案夾取名zxing,

然後從https://github.com/zxing/zxing上把zxing下載下來。解壓開啟。由於zxing支援多個平台,而我們只需要支援ios的就行,所以我們只需要保留兩個檔案夾(cpp和iphone)即可,把兩個檔案夾複製出來,放到第一步建立的zxing的檔案夾下面。

 

接著我們接續把不需要的檔案給刪了。對於cpp/core/src檔案夾下面的東西,我們只保留bigint和zxing兩個檔案夾。

對於iphone檔案夾,我們需要刪除iphone/ZXingWidget目錄下面的Tests檔案夾。刪除後

接下來開啟我們的demo,把zxing目錄添加到我們的ios項目中,然後把iphone/ZXingWidget下面的ZXingWidget.xcodeproj檔案拖到和zxing同級目錄。(如果發現有tests檔案夾,就把tests檔案夾刪掉)


然後在項目中面板中點擊build phases tab,然後增加 Target Dependencies 和 Link binary,並且增加這些framework依賴,添加後

在設定中增加兩個header search path ,需要注意的是,第一個path要設定成迴圈超找字幕了,而第二個不迴圈尋找,如所示:

 

到這一步,我們就把ZXing庫給整合好了。這個時候編譯一下,看是否報錯。很可惜,的確會報錯,錯誤類型為:

這時,我們找到有錯誤的那行代碼,雙擊代碼左邊的紅圓點,會彈出如提示:

 

然後雙擊第二行(帶藍色底的那行),這時發現錯誤神奇的消失了。

 

在我們的類加入zxing的依賴關係。

#import <ZXingWidgetController.h>

#import <QRCodeReader.h>

這個是我們畫的介面:

 

在.m中我們這樣寫:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - (IBAction)zxingAction:(id)sender {     ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];     NSMutableSet *readers = [[NSMutableSet alloc ] init];     QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];     [readers addObject:qrcodeReader];     [qrcodeReader release];     widController.readers = readers;     [readers release];     [self presentViewController:widController animated:YES completion:nil];     [widController release]; } - (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {     self.showTextView.text = result;     [controller dismissViewControllerAnimated:YES completion:nil]; }   - (void)zxingControllerDidCancel:(ZXingWidgetController *)controller {     [controller dismissViewControllerAnimated:YES completion:nil]; }

這個時候編譯一下,會報‘iosstream‘ file not found 錯誤,這時我們需要把.m檔案改為.mm檔案,和調用這個類的.m檔案,改為.mm檔案。詳細請參考:http://stackoverflow.com/questions/8154024/iostream-file-not-found-in-xcode-4-2

修改後

 

因為我在SSViewController的標頭檔中引入了

#import <ZXingWidgetController.h>

#import <QRCodeReader.h>

而且在SSViewController.m中使用了ZXingWidgetController,而ZXingWidgetController裡面有C++代碼,所以需要把SSViewController的尾碼變為.mm。因為SSAppDelegate中調用了SSViewController,所以也要把.m尾碼變為.mm。

然後再編譯一下,發現編譯成功了。那麼我們的教程也就結束了。

注意事項

 

這時因為沒有刪除ZXingWidget項目中的Tests檔案夾,刪除掉就OK 了。

 

2,在刪了Tests檔案夾後,編譯發現還會報錯,

 

這是因為,沒有把ZXingWidget.xcodeproj拖到和zxing同級目錄,拖ZXingWidget.xcodeproj到和zxing同級目錄

3,有的人不喜歡把zxing檔案和.xcodeproj放在同一級目錄下面,就像我們的demo那樣。如果放在其他地方也可以,這是需要修改header search path中的路徑。如果我們把zxing放到TestZXing目錄下面,

 

這時需要修改header search path為:

 

分享自:http://hi.baidu.com/_delegate/item/56ef8c034c2c3d1aaddc7081

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.