Ext.: http://blog.csdn.net/brokge/article/details/9045629
Recently done Android and iOS projects with the zxing QR code scanning, which in iOS integration is more troublesome, encountered many problems.
The first half of the article is part of the basic section from this article: http://blog.devtang.com/blog/2012/12/23/use-zxing-library/
It's more clearly written.
The following are the problems and solutions that have been encountered in the integration process, and the integrated code can be seen in the attachment (including, iOS and Android), where it is shared with everyone.
ZXing (GitHub mirror address) is an open source barcode generation and scanning library (open source protocol for Apache2.0). It supports a wide range of barcode formats and is available in a variety of languages, including: Java, C + +, C #, Objective-c, ActionScript and Ruby.
iOS articles
Integration steps
First go to Google Code or github to download zxing code, the whole project is relatively large, we only need to involve the part of iOS, so it is best to do some cutting. Simply put, we only need to keep the 2 folders of CPP and iphone, and all the rest are erased. As shown in the following:
Then we continue to crop, for the CPP this directory, only keep cpp/core/src/zxing below the content, the rest of the content can also be deleted. However, the entire directory structure must remain intact. After cropping, the entire directory structure is as follows:
Next, we move the cropped zxing directory to the directory of our iOS project, and drag the visible zxingwidget.xcodeproj file to our iOS project.
Next, we need to set the dependency between the Zxing project and our original iOS project. In the settings for our iOS project, click Build Phases tab, then add Target Dependencies and Link binary, and increase these framework dependencies:
- <span style="FONT-SIZE:14PX;" >a. Avfoundation
- B. Audiotoolbox
- C. corevideo
- D. CoreMedia
- E. Libiconv
- F. AddressBook
- G. addressbookui</span>
After completion as shown:
In the final step, add the following 2 header search path to the settings:
- ./zxing/iphone/zxingwidget/classes
- ./zxing/cpp/core/src
It is important to note that the first path is set to loop to find subdirectories, while the second one does not loop lookups as shown in:
Congratulations, after completing this step, you have completed the integration of the Zxing library. Here is how to use the Zxing library to do two-dimensional code recognition.
Two-dimensional code recognition using method
Zxing directly provides a view Controller that scans the QR code, which is Zxingwidgetcontroller. In the interface code you need to use, include file dependencies:
CPP Code
- <span style="FONT-SIZE:14PX;" > #import <ZXingWidgetController.h>
- #import <QRCodeReader.h> </span>
Then, when you need to scan, call the following code:
CPP Code
- <span style="FONT-SIZE:14PX;" >-(ibaction) scanpressed: (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 Presentmodalviewcontroller:widcontroller animated:yes];
- [Widcontroller release];
- }</span>
When the zxing scan has a result, the following callback function is called:
CPP Code
- <span style="FONT-SIZE:14PX;" > @protocol zxingdelegate
- -(void) Zxingcontroller: (zxingwidgetcontroller*) controller didscanresult: (NSString *) result;
- -(void) Zxingcontrollerdidcancel: (zxingwidgetcontroller*) controller;
- @end </span>
Problems and Solutions encountered:
I have encountered some problems in the use, mainly is the problem of compiling.
- One is not finding the head file. Workaround: Change the source file extension used to zxing from. m to. mm.
-
Error: Undefined symbols for Architecture armv7s, Workaround: (1) A build target parameter of Zxingwidget: "Build Active architecture only" is modified to "NO". (2) Change main.m to MAIN.MM
- Error: No such file or directory, it may be your header Search path is wrong, or your zxing library directory structure is not what I emphasized above, check it carefully.
- If you need to generate two-dimensional code to do the test, recommend a good online generation QR Code of the website: http://cli.im/
- error: IOStream File not found, solution The introduction of Zxingwidgetcontroller viewcontroller and appdelegate and main also need to be modified to. mm, error after modification: Span class= "S6" >undefined symbols for Architecture I386:
"Std::string::c_str () Const "Modified: TARGETS, Build Settings, Apple LLVM compiler 4.2-language
Set C + + standard Library A value of compiler Default
Zxingwidget Project:
TARGETS, Build Settings Architectures
Set the value of architectures to standard (ARMV7, armv7s)
/span>
- Error:clang:error:invalid deployment target for-stdlib=libc++ (requires IOS 5.0 or later): Workaround: Convert the clan in target The G_cxx_library entry is set to Libstdc++
Ps:
1, uint8_t* baseaddress = (uint8_t *)cvpixelbuffergetbaseaddress(imagebuffer); this type conversion
2,c++ Standard library Selection:
IOS zxing Integration