2013年8月23日 星期五

iOS整合ZXing(QRcode & Barcode reader)


The issue you have encountered seems to be C++ standard library related.
Actually, whenever you see linker failures in relationship with standard library objects (e.g. std::string), you should check the project settings on all linked libraries and the app-project itself. They usually need to match!
The original ScanTest (which builds ZXingWidget as a subproject) uses the following settings and those need to match your App build-settings if you use the library as is.
For making sure, I created a brand-new project using Xcode 4.5. That project uses ZXingWidget as a prebuilt library but not as a subproject - I dont like subprojects for stuff that is not my own - though this specialty wont influence the results.
The important setting is C++ Standard Library - make sure that is set towards Compiler Default

如果依下列步驟整合進專案仍發生compile錯誤,則檢查你專案的Build Setting下的Apple LLVM compiler 4.2 - Language 裡的 C++ Standard Library是否設為Compiler Default

[以下節錄自http://noteforios.blogspot.tw/2012/09/zxing.html]
1.取得ZXing
連至http://code.google.com/p/zxing/取得,目前版本為2.2。

2.加入ZXing到專案中
ZXing支援很多平台,請依序點選進入資料夾中

zxing >iphone > ZXingWidget

將ZXingWidget.xcodeproj拖曳至專案中,如果出現提示,請注意請勿勾選複製選項,請以參考的方式加入。

3.設定Build Phases
選擇專案TAGETS,選擇Build Phases分頁
3.1 在Target Dependencies中,加入ZXingWidget (ZXingWidget)
3.2 在Link Binary With Libraries加入所需framework

  • libZXingWidget.a
  • libiconv.dylib
  • CoreVideo.framework
  • CoreMedia.framework
  • AVFoundation.framework
  • AudioToolbox.framework
  • AddressBook.framework
  • AddressBookUI.framework
4.設定Build Setting
在Build Setting中搜尋"Header Search Paths"
點選"+"號,增加搜尋路徑,這邊記得要提供完整路徑,
Full Path../zxing/cpp/core/src (選non-recursive)
Full Path../zxing/iphone/ZXingWidget/Classes (選recursive)
加入完成後要確定有被勾選才行

5.import
#import <ZXingWidgetController.h>
#import <QRCodeReader.h>

注意事項:
  1. 資料夾名稱請不要包含"空白",會導致XCode誤判。
  2. 因有使用到C++的編譯器,請記得將副檔名由.m變更為.mm。
  3. #import <qrcodereader.h>請寫在.mm中,不然編譯會錯誤。
  4. ZXingWidget.xcodeproj的Compiler要注意
  5. 目前不確定是否支援ARC與storybard,所以請不要使用該功能。

沒有留言:

張貼留言