iOS uses ZBARSDK to enable generation and scanning of two-dimensional code

Source: Internet
Author: User

Now the use of QR code is more and more, then we do the app, sometimes we need to consider the generation and scanning of two-dimensional code

Let's start with a simple two-dimensional code generation

First define a ImageView to display the generated QR code image

It's just a simple thing to do. Convert a string into a two-dimensional code

Import Libqrencode File

Introduction of header File #import "QRCodeGenerator.h" can be used

Imageview.image = [Qrcodegenerator qrimageforstring:@ "Www.cnblogs.com/myselfxiaoxiao" ImageSize: imageview.bounds.size.width];//This is a class method, the first parameter is the string that needs to be converted, and the second parameter is the size of the converted QR code.

Other ways of conversion can be studied on their own.

Mainly about the QR Code scan. Scan function needs to be tested on the real machine

Scan the QR Code section:

Import the Zbarsdk file and introduce the framework

Avfoundation.framework

Coremedia.framework

Corevideo.framework

Quartzcore.framework

Libiconv.dylib

Introduction of header File #import "ZBarSDK.h" can be used

Zbarreaderviewcontroller *reader = [Zbarreaderviewcontroller new]; Read Controller

Reader.readerdelegate = self; Signed agent, when reading to QR code or barcode will go the corresponding method used by the protocol is <ZBarReaderDelegate>

Reader.supportedorientationsmask = Zbarorientationmaskall; Basic adaptation

Zbarimagescanner *scanner = Reader.scanner; QR Code and barcode recognition settings

[Scanner setsymbology:zbar_i25

Config:zbar_cfg_enable

TO:0];

[Self Presentmodalviewcontroller:reader

Animated:yes]; Eject camera

[Reader release];

Next implement the Proxy method

-(void) Imagepickercontroller: (uiimagepickercontroller*) reader

Didfinishpickingmediawithinfo: (nsdictionary*) Info

{

id<nsfastenumeration> results =

[Info objectforkey:zbarreadercontrollerresults];

Zbarsymbol *symbol = nil;

for (symbol in results) {

Break

}

Imageview.image =

[Info objectforkey:uiimagepickercontrolleroriginalimage];

[Reader Dismissmodalviewcontrolleranimated:yes];

NSString *content = Symbol.data;

Next, for the information read to do the corresponding action, such as the URL, open the Web page, and so on.

}

iOS uses ZBARSDK to enable generation and scanning of two-dimensional code

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.