Zbar barcode QR code scanning control developed for iOS (91)

Source: Internet
Author: User

When we develop IOS applications, especially e-commerce applications, we often encounter bar code scanning business needs. Fortunately, we already have open-source sdks for us-bar code sdks for iOS, the following describes how to use this open-source SDK:

 

Free bar code is zbar, is: http://zbar.sourceforge.net

The specific implementation process is as follows:

Step 1: Download The zbar SDK.

Step 2: Create a project

Step 3: add the downloaded zbarsdk to the project.

Step 4: Add. Framework to the project.

 

Fifth, add the header file referenced by the Library

Sixth, add a button to control the scan function.

 

Code implementation:

1) Add the zbarreaderdelegate protocol to the. h file.

2) In the. m implementation file, implement the following code:

// Enable scanning and call the iPhone camera

 

-(Ibaction) scanbuttontapped

{

Zbarreaderviewcontroller * reader = [zbarreaderviewcontroller new];

Reader. readerdelegate = self;

Zbarimageworkflow * reader. Category = reader. category;

 

[Export setsymbology: zbar_i25

Config: zbar_assist_enable

To: 0];

 

[Self presentmodalviewcontroller: reader animated: Yes];

[READER release];

}

 

 

// Proxy method

 

-(Void) imagepickercontroller: (uiimagepickercontroller *) Reader

Didfinishpickingmediawithinfo: (nsdictionary *) info

{

 

Nslog (@ "info = % @", Info );

// Obtain the bar code result

ID <nsfastenumeration> Results =

[Info objectforkey: zbarreadercontrollerresults];

Zbarsymbol * symbol = nil;

For (symbol in results)

// Example: Just grab the first barcode

Break;

 

// Display the obtained barcode to our interface

Resulttext. Text = symbol. Data;

 

// The scanned image is displayed on our interface.

Resultimage. Image =

[Info objectforkey: uiimagepickercontrolleroriginalimage];

 

// Exit the scan interface

[READER dismissmodalviewcontrolleranimated: Yes];

}

 

 

Effect:

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.