IOS zxing Integration

Source: Internet
Author: User

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:

    1. <span style="FONT-SIZE:14PX;" >a. Avfoundation
    2. B. Audiotoolbox
    3. C. corevideo
    4. D. CoreMedia
    5. E. Libiconv
    6. F. AddressBook
    7. 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
    1. <span style="FONT-SIZE:14PX;" > #import <ZXingWidgetController.h>
    2. #import <QRCodeReader.h> </span>
Then, when you need to scan, call the following code:

CPP Code
  1. <span style="FONT-SIZE:14PX;" >-(ibaction) scanpressed: (ID) Sender {
  2. Zxingwidgetcontroller *widcontroller = [[Zxingwidgetcontroller alloc] initwithdelegate:self ShowCancel:YES OneDMode: NO];
  3. Nsmutableset *readers = [[Nsmutableset alloc] init];
  4. qrcodereader* Qrcodereader = [[Qrcodereader alloc] init];
  5. [Readers Addobject:qrcodereader];
  6. [Qrcodereader release];
  7. widcontroller.readers = readers;
  8. [Readers release];
  9. [Self Presentmodalviewcontroller:widcontroller animated:yes];
  10. [Widcontroller release];
  11. }</span>
When the zxing scan has a result, the following callback function is called:

CPP Code
    1. <span style="FONT-SIZE:14PX;" > @protocol zxingdelegate
    2. -(void) Zxingcontroller: (zxingwidgetcontroller*) controller didscanresult: (NSString *) result;
    3. -(void) Zxingcontrollerdidcancel: (zxingwidgetcontroller*) controller;
    4. @end </span>
Problems and Solutions encountered:

I have encountered some problems in the use, mainly is the problem of compiling.

  1. One is not finding the head file. Workaround: Change the source file extension used to zxing from. m to. mm.
  2. 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

  3. 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.
  4. 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/
  5. 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>
  6. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.