Ios qr code demo and barcode demo

Source: Internet
Author: User

Demo download: http://download.csdn.net/download/qingsi00/5001589

Today, QR codes are everywhere, and QR codes are indispensable for physical products and coupons.

Mobile devices such as mobile phones have become a good application platform for QR codes, whether generating or scanning QR codes.

The following describes how to use a QR code on an apple iOS device:

1. Scan the QR code (Decoding)
There are many open-source libraries for scanning QR codes, such as zbar and zxing. Here we use zbar as an example to build a QR code scanning application.
First download the zbar SDK https://github.com/bmorton/ZBarSDK on GitHub
Open the compressed package. The zbarsdk folder contains the zbarsdk folder in the project.
(Finder)
(Xcode)
It contains a static library of libzbar..
Add the Framework framework and link library (dynamic library and static library) to the project ). In the project properties targets-> summary, find linked frameworks and libraries
Add avfoundation. framwork, coremedia. Framework, corevideo. Framework, libiconv. dylib, and libzbar.
()


Then introduce the header file where it is used.

# Import "zbarsdk. H"
The zbarreaderdelegate protocol must be implemented for the class that calls zbar.
For example, uiviewcontroller <zbarreaderdelegate>

The source file is as follows:

-(Bool) Application: (uiapplication *) Application

Didfinishlaunchingwitexceptions: (nsdictionary *) Options

{

Self. Window. rootviewcontroller = self. tabbarcontroller;

[Self. Window makekeyandvisible];

// Force class to load so it may be referenced directly from nib

[Zbarreaderviewcontroller
Class];

Zbarreaderviewcontroller * reader =

[Self. tabbarcontroller. viewcontrollers
Objectatindex: 0];

Reader. readerdelegate =
Self;

Reader. showszbarcontrols =
No;

Reader. supportedorientationsmask =
Zbarorientationmaskall;

Return (yes );

}

// Zbarreaderdelegate

-(Void) imagepickercontroller: (uiimagepickercontroller *) picker

Didfinishpickingmediawithinfo: (nsdictionary *) info

{

// Do something useful with results

Uitabbarcontroller * tabs =
Self. tabbarcontroller;

Tabs. selectedindex =
1;


Resultsviewcontroller * Results = [tabs. viewcontrollers
Objectatindex: 1];

Uiimage * image = [info
Objectforkey:
Uiimagepickercontrolleroriginalimage];

Results. resultimage. Image = image;

ID <nsfastenumeration> Syms =

[Info objectforkey:
Zbarreadercontrollerresults];


For (zbarsymbol * sym
In Syms ){

Results. resulttext. Text = sym. Data;


Break;

}

}

2. Generate a QR code)
Qrencoder is easier to use in the library that generates the QR code. The Android version of The zxing library is a Java-based encoding library, but I do not know why the C ++ version does not exist. Therefore, it cannot be decoded on IOS, if the application needs to generate a QR code and scan the QR code, there may be two sets of different libraries.
First, download it to the SDK library on GitHub.
Address https://github.com/jverkoey/ObjQREncoder
Decompress the package and directly include the source code library in the project ()

Set the header file path. In the target, create settings search path

Of course, you can also directly compile the library into the static library libqrecoder. A and then include it in

Then add a reference to the static library in frameworks.


Then, include the header file where the library is used.
# Import <qrencoder/qrencoder. h>
Note: The image size may be adjusted when the QR code is displayed. Therefore, the system library quartzcore. framework must be included.
Finally, you can call the encoding library:

[CPP]View
Plaincopy

  1. Uiimage * image = [qrencoder encode: @ "http://www.baidu.com/"];


Note that no QR code is generated in the demo. Add it later.

Demo download: http://download.csdn.net/download/qingsi00/5001589

Related Article

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.